1/*
2 * Copyright (c) 2021-2022 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
16#ifndef RESULT_CONVERT_H
17#define RESULT_CONVERT_H
18
19#include <map>
20#include <string>
21
22#include "contacts_napi_common.h"
23#include "napi/native_common.h"
24#include "napi/native_node_api.h"
25#include "result_set.h"
26
27namespace OHOS {
28namespace ContactsApi {
29class ResultConvert {
30public:
31    ResultConvert();
32    ~ResultConvert();
33    napi_value GetNapiValue(napi_env env, const std::string keyChar, napi_value object);
34    napi_value GetNapiElementArray(napi_env env, napi_value object, const std::string keyChar);
35    napi_value GetNapiElementObject(napi_env env, napi_value object, const std::string keyChar);
36    napi_value GetResultValue(
37        napi_env env, std::string &contentKey, std::shared_ptr<DataShare::DataShareResultSet> &resultSet);
38    napi_value ResultSetToHolder(napi_env env, std::shared_ptr<DataShare::DataShareResultSet> &resultSet);
39    napi_value ResultSetToGroup(napi_env env, std::shared_ptr<DataShare::DataShareResultSet> &resultSet);
40    napi_value ResultSetToObject(napi_env env, std::shared_ptr<DataShare::DataShareResultSet> &resultSet);
41    napi_value ConvertContactArray(
42        napi_env env, std::map<int, napi_value> &resultSetMap, std::map<int, std::string> &quickSearchMap);
43    void PutQuickSearchKey(napi_env env, std::shared_ptr<DataShare::DataShareResultSet> &resultSet,
44        std::map<int, std::string> &quickSearchMap, int contactsIdValue);
45    void ConvertContactObject(
46        napi_env env, napi_value napiObject, std::shared_ptr<DataShare::DataShareResultSet> &resultSet);
47    napi_value GetResultMapValue(napi_env env, std::map<int, napi_value> &resultSetMap, int &contactsId);
48    void ConvertEmail(napi_env env, napi_value napiObject, int &typeId,
49        std::shared_ptr<DataShare::DataShareResultSet> &resultSet);
50    void ConvertName(napi_env env, napi_value napiObject, int &typeId,
51        std::shared_ptr<DataShare::DataShareResultSet> &resultSet);
52    void ConvertUri(napi_env env, napi_value napiObject, int &typeId,
53        std::shared_ptr<DataShare::DataShareResultSet> &resultSet);
54    void ConvertEvent(napi_env env, napi_value napiObject, int &typeId,
55        std::shared_ptr<DataShare::DataShareResultSet> &resultSet);
56    void ConvertGroup(napi_env env, napi_value napiObject, int &typeId,
57        std::shared_ptr<DataShare::DataShareResultSet> &resultSet);
58    void ConvertImAddress(napi_env env, napi_value napiObject, int &typeId,
59        std::shared_ptr<DataShare::DataShareResultSet> &resultSet);
60    void ConvertPhoneNumber(napi_env env, napi_value napiObject, int &typeId,
61        std::shared_ptr<DataShare::DataShareResultSet> &resultSet);
62    void ConvertPostalAddress(napi_env env, napi_value napiObject, int &typeId,
63        std::shared_ptr<DataShare::DataShareResultSet> &resultSet);
64    void ConvertRelation(napi_env env, napi_value napiObject, int &typeId,
65        std::shared_ptr<DataShare::DataShareResultSet> &resultSet);
66    void ConvertSipAddress(napi_env env, napi_value napiObject, int &typeId,
67        std::shared_ptr<DataShare::DataShareResultSet> &resultSet);
68    void ConvertWebsite(napi_env env, napi_value napiObject, int &typeId,
69        std::shared_ptr<DataShare::DataShareResultSet> &resultSet);
70    void ConvertNickName(napi_env env, napi_value napiObject, int &typeId,
71        std::shared_ptr<DataShare::DataShareResultSet> &resultSet);
72    void ConvertNote(napi_env env, napi_value napiObject, int &typeId,
73        std::shared_ptr<DataShare::DataShareResultSet> &resultSet);
74    void ConvertOrganization(napi_env env, napi_value napiObject, int &typeId,
75        std::shared_ptr<DataShare::DataShareResultSet> &resultSet);
76    napi_value CreateNapiStringValue(napi_env env, const std::string key);
77    bool IsEmpty(std::shared_ptr<DataShare::DataShareResultSet> &resultSet);
78};
79} // namespace ContactsApi
80} // namespace OHOS
81#endif // RESULT_CONVERT_H
82