001package com.plivo.api.models.compliancedocument;
002
003import com.plivo.api.exceptions.ResourceNotFoundException;
004import com.plivo.api.models.base.Updater;
005import okhttp3.MediaType;
006import okhttp3.MultipartBody;
007import okhttp3.RequestBody;
008import retrofit2.Call;
009
010import javax.activation.MimetypesFileTypeMap;
011import java.io.File;
012import java.io.IOException;
013import java.nio.file.Files;
014import java.nio.file.Path;
015import java.nio.file.Paths;
016
017public class ComplianceDocumentUpdater extends Updater<ComplianceDocumentUpdateResponse> {
018
019    private String endUserId;
020    private String alias;
021    private String documentTypeId;
022    private String file;
023    private String addressLine1;
024    private String addressLine2;
025    private String city;
026    private String country;
027    private String postalCode;
028    private String lastName;
029    private String firstName;
030    private String dateOfBirth;
031    private String uniqueIdentificationNumber;
032    private String businessName;
033    private String authorizedRepresentativeName;
034    private String nationality;
035    private enum typeOfUtility {
036      water,electricity,gas, propertyRental, others
037    };
038    private String billId;
039    private String typeOfId;
040    private String placeOfBirth;
041    private String dateOfIssue;
042    private String dateOfExpiration;
043    private String billDate;
044    private String supportEmail;
045    private String supportPhoneNumber;
046    private String useCaseDescription;
047    private MultipartBody.Builder body;
048
049
050
051
052    public ComplianceDocumentUpdater(String id) {
053        super(id);
054        this.body = new MultipartBody.Builder().setType(MultipartBody.FORM);
055    }
056
057    public ComplianceDocumentUpdater setPostalCode(String postalCode) {
058        this.postalCode = postalCode;
059        this.body.addFormDataPart("postal_code", postalCode);
060        return this;
061    }
062
063    public ComplianceDocumentUpdater setLastName(String lastName) {
064        this.lastName = lastName;
065        this.body.addFormDataPart("last_name", lastName);
066        return this;
067    }
068
069    public ComplianceDocumentUpdater setFirstName(String firstName) {
070        this.firstName = firstName;
071        this.body.addFormDataPart("first_name", firstName);
072        return this;
073    }
074
075    public ComplianceDocumentUpdater setFile(String file) throws ResourceNotFoundException {
076      this.file = file;
077      File tempFile = new File(file);
078      boolean exists = tempFile.exists();
079      if (!exists)
080        throw new ResourceNotFoundException("File missing " + file);
081      try {
082        System.out.println(tempFile);
083        System.out.println(tempFile.toPath());
084        // handle for java 8
085        String content_type = "";
086        if (Files.probeContentType(tempFile.toPath()) != null) {
087          content_type = Files.probeContentType(tempFile.toPath());
088        } else {
089          Path source = Paths.get(file);
090          MimetypesFileTypeMap m = new MimetypesFileTypeMap(source.toString());
091          content_type = m.getContentType(tempFile);
092        }
093        this.body
094          .addFormDataPart("file", file,
095            RequestBody.create(MediaType.parse(content_type), tempFile));
096      } catch (IOException e) {
097        throw new ResourceNotFoundException("Unable to read file " + file);
098      }
099      return this;
100    }
101
102
103
104    public ComplianceDocumentUpdater setEndUserId(String endUserId) {
105        this.endUserId = endUserId;
106      this.body.addFormDataPart("end_user_id", endUserId);
107        return this;
108    }
109
110    public ComplianceDocumentUpdater setDocumentTypeId(String documentTypeId) {
111        this.documentTypeId = documentTypeId;
112      this.body.addFormDataPart("document_type_id", documentTypeId);
113        return this;
114    }
115
116    public ComplianceDocumentUpdater setDateOfBirth(String dateOfBirth) {
117        this.dateOfBirth = dateOfBirth;
118      this.body.addFormDataPart("date_of_birth", dateOfBirth);
119        return this;
120    }
121
122    public ComplianceDocumentUpdater setCountry(String country) {
123        this.country = country;
124      this.body.addFormDataPart("country", country);
125        return this;
126    }
127
128    public ComplianceDocumentUpdater setCity(String city) {
129        this.city = city;
130      this.body.addFormDataPart("city", city);
131        return this;
132    }
133
134    public ComplianceDocumentUpdater setAlias(String alias) {
135        this.alias = alias;
136      this.body.addFormDataPart("alias", alias);
137        return this;
138    }
139
140    public ComplianceDocumentUpdater setAddressLine2(String addressLine2) {
141        this.addressLine2 = addressLine2;
142      this.body.addFormDataPart("address_line_2", addressLine2);
143        return this;
144    }
145
146    public ComplianceDocumentUpdater setAddressLine1(String addressLine1) {
147        this.addressLine1 = addressLine1;
148        this.body.addFormDataPart("address_line_1", addressLine1);
149        return this;
150    }
151
152    public ComplianceDocumentUpdater setUniqueIdentificationNumber(String uniqueIdentificationNumber) {
153        this.uniqueIdentificationNumber = uniqueIdentificationNumber;
154        this.body.addFormDataPart("unique_identification_number", uniqueIdentificationNumber);
155        return this;
156    }
157
158    public ComplianceDocumentUpdater setBusinessName(String businessName) {
159      this.businessName = businessName;
160      this.body.addFormDataPart("business_name", businessName);
161      return this;
162    }
163
164    public ComplianceDocumentUpdater setAuthorizedRepresentativeName(String authorizedRepresentativeName) {
165      this.authorizedRepresentativeName = authorizedRepresentativeName;
166      this.body.addFormDataPart("authorized_representative_name", authorizedRepresentativeName);
167      return this;
168    }
169
170    public ComplianceDocumentUpdater setNationality(String nationality) {
171      this.nationality = nationality;
172      this.body.addFormDataPart("nationality", nationality);
173      return this;
174    }
175
176    public ComplianceDocumentUpdater setBillId(String billId) {
177      this.billId = billId;
178      this.body.addFormDataPart("bill_id", billId);
179      return this;
180    }
181
182    public ComplianceDocumentUpdater setTypeOfId(String typeOfId) {
183      this.typeOfId = typeOfId;
184      this.body.addFormDataPart("type_of_id", typeOfId);
185      return this;
186    }
187
188    public ComplianceDocumentUpdater setPlaceOfBirth(String placeOfBirth) {
189      this.placeOfBirth = placeOfBirth;
190      this.body.addFormDataPart("place_of_birth", placeOfBirth);
191      return this;
192    }
193
194    public ComplianceDocumentUpdater setDateOfIssue(String dateOfIssue) {
195      this.dateOfIssue = dateOfIssue;
196      this.body.addFormDataPart("date_of_issue", dateOfIssue);
197      return this;
198    }
199
200    public ComplianceDocumentUpdater setDateOfExpiration(String dateOfExpiration) {
201      this.dateOfExpiration = dateOfExpiration;
202      this.body.addFormDataPart("date_of_expiration", dateOfExpiration);
203      return this;
204    }
205
206    public ComplianceDocumentUpdater setBillDate(String billDate) {
207      this.billDate = billDate;
208      this.body.addFormDataPart("bill_date", billDate);
209      return this;
210    }
211
212    public ComplianceDocumentUpdater setSupportEmail(String supportEmail) {
213      this.supportEmail = supportEmail;
214      this.body.addFormDataPart("support_email", supportEmail);
215      return this;
216    }
217
218    public ComplianceDocumentUpdater setSupportPhoneNumber(String supportPhoneNumber) {
219      this.supportPhoneNumber = supportPhoneNumber;
220      this.body.addFormDataPart("support_phone_number", supportPhoneNumber);
221      return this;
222    }
223
224    public ComplianceDocumentUpdater setUseCaseDescription(String useCaseDescription) {
225      this.useCaseDescription = useCaseDescription;
226      this.body.addFormDataPart("use_case_description", useCaseDescription);
227      return this;
228    }
229
230
231
232    @Override
233    protected Call<ComplianceDocumentUpdateResponse> obtainCall() {
234        return client().getApiService().complianceDocumentUpdate(client().getAuthId(), id, this.body.build());
235    }
236}