18779efd5Sopenharmony_ci/**
28779efd5Sopenharmony_ci * Copyright (c) 2022 Huawei Device Co., Ltd.
38779efd5Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
48779efd5Sopenharmony_ci * you may not use this file except in compliance with the License.
58779efd5Sopenharmony_ci * You may obtain a copy of the License at
68779efd5Sopenharmony_ci *
78779efd5Sopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
88779efd5Sopenharmony_ci *
98779efd5Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software
108779efd5Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
118779efd5Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
128779efd5Sopenharmony_ci * See the License for the specific language governing permissions and
138779efd5Sopenharmony_ci * limitations under the License.
148779efd5Sopenharmony_ci */
158779efd5Sopenharmony_ci
168779efd5Sopenharmony_ciimport RawContact from './RawContact';
178779efd5Sopenharmony_ciimport Contact from './Contact';
188779efd5Sopenharmony_ciimport { Contacts } from '../contract/Contacts';
198779efd5Sopenharmony_ciimport { Data } from '../contract/Data';
208779efd5Sopenharmony_ciimport { RawContacts } from '../contract/RawContacts';
218779efd5Sopenharmony_ci
228779efd5Sopenharmony_ci/**
238779efd5Sopenharmony_ci * Call log constructor
248779efd5Sopenharmony_ci */
258779efd5Sopenharmony_ciexport default class ContactBuilder {
268779efd5Sopenharmony_ci  readonly id: number;
278779efd5Sopenharmony_ci  nameRawContactId: number;
288779efd5Sopenharmony_ci  quickSearchKey: string;
298779efd5Sopenharmony_ci  photoId: number;
308779efd5Sopenharmony_ci  photoFileId: number;
318779efd5Sopenharmony_ci  personalRingtone: string;
328779efd5Sopenharmony_ci  personalNotificationRingtone: string;
338779efd5Sopenharmony_ci  isTransferVoiceMail: boolean;
348779efd5Sopenharmony_ci  company: string;
358779efd5Sopenharmony_ci  position: string;
368779efd5Sopenharmony_ci  hasDisplayName: boolean;
378779efd5Sopenharmony_ci  hasPhoneNumber: boolean;
388779efd5Sopenharmony_ci  readOnly: boolean;
398779efd5Sopenharmony_ci  hasGroup: boolean;
408779efd5Sopenharmony_ci  hasEmail: boolean;
418779efd5Sopenharmony_ci  rowContacts: RawContact[];
428779efd5Sopenharmony_ci
438779efd5Sopenharmony_ci  constructor(id: number) {
448779efd5Sopenharmony_ci    this.id = id;
458779efd5Sopenharmony_ci  }
468779efd5Sopenharmony_ci
478779efd5Sopenharmony_ci  static fromResultSet(resultSet: any): ContactBuilder{
488779efd5Sopenharmony_ci    let contactBuilder = new ContactBuilder(resultSet.getLong(resultSet.getColumnIndex(RawContacts.CONTACT_ID)));
498779efd5Sopenharmony_ci    contactBuilder.setNameRawContactId(resultSet.getLong(resultSet.getColumnIndex(Data.RAW_CONTACT_ID)));
508779efd5Sopenharmony_ci    contactBuilder.setQuickSearchKey(resultSet.getString(resultSet.getColumnIndex(Contacts.QUICK_SEARCH_KEY)));
518779efd5Sopenharmony_ci    contactBuilder.setPhotoId(resultSet.getLong(resultSet.getColumnIndex(Contacts.PHOTO_ID)));
528779efd5Sopenharmony_ci    contactBuilder.setPhotoFileId(resultSet.getLong(resultSet.getColumnIndex(Contacts.PHOTO_FILE_ID)));
538779efd5Sopenharmony_ci    contactBuilder.setPersonalRingtone(resultSet.getString(resultSet.getColumnIndex(Contacts.PERSONAL_RINGTONE)));
548779efd5Sopenharmony_ci    contactBuilder.setPersonalNotificationRingtone(resultSet.getString(resultSet.getColumnIndex(Contacts.PERSONAL_NOTIFICATION_RINGTONE)));
558779efd5Sopenharmony_ci    contactBuilder.setIsTransferVoiceMail(resultSet.getLong(resultSet.getColumnIndex(Contacts.IS_TRANSFER_VOICEMAIL)) > 0 ? true : false);
568779efd5Sopenharmony_ci    contactBuilder.setCompany(resultSet.getString(resultSet.getColumnIndex(Contacts.COMPANY)));
578779efd5Sopenharmony_ci    contactBuilder.setPosition(resultSet.getString(resultSet.getColumnIndex(Contacts.POSITION)));
588779efd5Sopenharmony_ci    contactBuilder.setHasDisplayName(resultSet.getLong(resultSet.getColumnIndex(Contacts.HAS_DISPLAY_NAME)) > 0 ? true : false);
598779efd5Sopenharmony_ci    contactBuilder.setHasEmail(resultSet.getLong(resultSet.getColumnIndex(Contacts.IS_TRANSFER_VOICEMAIL)) > 0 ? true : false);
608779efd5Sopenharmony_ci    contactBuilder.setHasGroup(resultSet.getLong(resultSet.getColumnIndex(Contacts.HAS_GROUP)) > 0 ? true : false);
618779efd5Sopenharmony_ci    contactBuilder.setHasPhoneNumber(resultSet.getLong(resultSet.getColumnIndex(Contacts.HAS_PHONE_NUMBER)) > 0 ? true : false);
628779efd5Sopenharmony_ci    contactBuilder.setReadOnly(resultSet.getLong(resultSet.getColumnIndex(Contacts.READ_ONLY)) > 0 ? true : false);
638779efd5Sopenharmony_ci    contactBuilder.setRowContacts([]);
648779efd5Sopenharmony_ci    return contactBuilder;
658779efd5Sopenharmony_ci  }
668779efd5Sopenharmony_ci
678779efd5Sopenharmony_ci  setNameRawContactId(nameRawContactId: number) {
688779efd5Sopenharmony_ci    this.nameRawContactId = nameRawContactId;
698779efd5Sopenharmony_ci    return this;
708779efd5Sopenharmony_ci  }
718779efd5Sopenharmony_ci
728779efd5Sopenharmony_ci  setPhotoId(photoId: number) {
738779efd5Sopenharmony_ci    this.photoId = photoId;
748779efd5Sopenharmony_ci    return this;
758779efd5Sopenharmony_ci  }
768779efd5Sopenharmony_ci
778779efd5Sopenharmony_ci  setPhotoFileId(photoFileId: number) {
788779efd5Sopenharmony_ci    this.photoFileId = photoFileId;
798779efd5Sopenharmony_ci    return this;
808779efd5Sopenharmony_ci  }
818779efd5Sopenharmony_ci
828779efd5Sopenharmony_ci  setQuickSearchKey(quickSearchKey: string) {
838779efd5Sopenharmony_ci    this.quickSearchKey = quickSearchKey;
848779efd5Sopenharmony_ci    return this;
858779efd5Sopenharmony_ci  }
868779efd5Sopenharmony_ci
878779efd5Sopenharmony_ci  setPersonalNotificationRingtone(personalNotificationRingtone: string) {
888779efd5Sopenharmony_ci    this.personalNotificationRingtone = personalNotificationRingtone;
898779efd5Sopenharmony_ci    return this;
908779efd5Sopenharmony_ci  }
918779efd5Sopenharmony_ci
928779efd5Sopenharmony_ci  setPersonalRingtone(personalRingtone: string) {
938779efd5Sopenharmony_ci    this.personalRingtone = personalRingtone;
948779efd5Sopenharmony_ci    return this;
958779efd5Sopenharmony_ci  }
968779efd5Sopenharmony_ci
978779efd5Sopenharmony_ci  setIsTransferVoiceMail(isTransferVoiceMail: boolean) {
988779efd5Sopenharmony_ci    this.isTransferVoiceMail = isTransferVoiceMail;
998779efd5Sopenharmony_ci    return this;
1008779efd5Sopenharmony_ci  }
1018779efd5Sopenharmony_ci
1028779efd5Sopenharmony_ci  setCompany(company: string) {
1038779efd5Sopenharmony_ci    this.company = company;
1048779efd5Sopenharmony_ci    return this;
1058779efd5Sopenharmony_ci  }
1068779efd5Sopenharmony_ci
1078779efd5Sopenharmony_ci  setPosition(position: string) {
1088779efd5Sopenharmony_ci    this.position = position;
1098779efd5Sopenharmony_ci    return this;
1108779efd5Sopenharmony_ci  }
1118779efd5Sopenharmony_ci
1128779efd5Sopenharmony_ci  setHasDisplayName(hasDisplayName: boolean) {
1138779efd5Sopenharmony_ci    this.hasDisplayName = hasDisplayName;
1148779efd5Sopenharmony_ci    return this;
1158779efd5Sopenharmony_ci  }
1168779efd5Sopenharmony_ci
1178779efd5Sopenharmony_ci  setReadOnly(readOnly: boolean) {
1188779efd5Sopenharmony_ci    this.readOnly = readOnly;
1198779efd5Sopenharmony_ci    return this;
1208779efd5Sopenharmony_ci  }
1218779efd5Sopenharmony_ci
1228779efd5Sopenharmony_ci  setHasPhoneNumber(hasPhoneNumber: boolean) {
1238779efd5Sopenharmony_ci    this.hasPhoneNumber = hasPhoneNumber;
1248779efd5Sopenharmony_ci    return this;
1258779efd5Sopenharmony_ci  }
1268779efd5Sopenharmony_ci
1278779efd5Sopenharmony_ci  setHasGroup(hasGroup: boolean) {
1288779efd5Sopenharmony_ci    this.hasGroup = hasGroup;
1298779efd5Sopenharmony_ci    return this;
1308779efd5Sopenharmony_ci  }
1318779efd5Sopenharmony_ci
1328779efd5Sopenharmony_ci  setHasEmail(hasEmail: boolean) {
1338779efd5Sopenharmony_ci    this.hasEmail = hasEmail;
1348779efd5Sopenharmony_ci    return this;
1358779efd5Sopenharmony_ci  }
1368779efd5Sopenharmony_ci
1378779efd5Sopenharmony_ci  setRowContacts(rowContacts: RawContact[]) {
1388779efd5Sopenharmony_ci    this.rowContacts = rowContacts;
1398779efd5Sopenharmony_ci    return this;
1408779efd5Sopenharmony_ci  }
1418779efd5Sopenharmony_ci
1428779efd5Sopenharmony_ci  buildContact() {
1438779efd5Sopenharmony_ci    return new Contact(this);
1448779efd5Sopenharmony_ci  }
1458779efd5Sopenharmony_ci}