1 /*
2  * Copyright (C) 2023 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 #include "vcard_phone_data.h"
16 
17 #include "telephony_errors.h"
18 
19 namespace OHOS {
20 namespace Telephony {
21 
BuildValuesBucket(OHOS::DataShare::DataShareValuesBucket & valuesBucket)22 int32_t VCardPhoneData::BuildValuesBucket(OHOS::DataShare::DataShareValuesBucket &valuesBucket)
23 {
24     valuesBucket.Put(ContactData::TYPE_ID, TypeId::PHONE);
25     valuesBucket.Put(ContactData::DETAIL_INFO, number_);
26     valuesBucket.Put(ContactData::LABEL_ID, labelId_);
27     valuesBucket.Put(ContactData::LABEL_NAME, labelName_);
28     return TELEPHONY_SUCCESS;
29 }
30 
BuildData(std::shared_ptr<DataShare::DataShareResultSet> resultSet)31 int32_t VCardPhoneData::BuildData(std::shared_ptr<DataShare::DataShareResultSet> resultSet)
32 {
33     if (resultSet == nullptr) {
34         return TELEPHONY_ERROR;
35     }
36     int32_t index;
37     resultSet->GetColumnIndex(ContactData::DETAIL_INFO, index);
38     resultSet->GetString(index, number_);
39     resultSet->GetColumnIndex(ContactData::LABEL_NAME, index);
40     resultSet->GetString(index, labelName_);
41     resultSet->GetColumnIndex(ContactData::LABEL_ID, index);
42     resultSet->GetString(index, labelId_);
43     return TELEPHONY_SUCCESS;
44 }
45 
InitPhoneData(std::string data,int32_t type,std::string label,bool isPrimary)46 void VCardPhoneData::InitPhoneData(std::string data, int32_t type, std::string label, bool isPrimary)
47 {
48     number_ = data;
49     labelId_ = std::to_string(type);
50     labelName_ = label;
51 }
52 
GetNumber()53 std::string VCardPhoneData::GetNumber()
54 {
55     return number_;
56 }
57 
SetNumber(const std::string & number)58 void VCardPhoneData::SetNumber(const std::string &number)
59 {
60     number_ = number;
61 }
62 
GetLabelId()63 std::string VCardPhoneData::GetLabelId()
64 {
65     return labelId_;
66 }
67 
SetLabelId(const std::string & labelId)68 void VCardPhoneData::SetLabelId(const std::string &labelId)
69 {
70     labelId_ = labelId;
71 }
72 
GetLabelName()73 std::string VCardPhoneData::GetLabelName()
74 {
75     return labelName_;
76 }
77 
SetLabelName(const std::string & labelName)78 void VCardPhoneData::SetLabelName(const std::string &labelName)
79 {
80     labelName_ = labelName;
81 }
82 
GetType()83 int32_t VCardPhoneData::GetType()
84 {
85     return type_;
86 }
87 
SetType(int32_t type)88 void VCardPhoneData::SetType(int32_t type)
89 {
90     type_ = type;
91 }
92 
93 } // namespace Telephony
94 } // namespace OHOS
95