1/*
2 * Copyright (C) 2021 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 DATA_STORAGE_RDB_SIM_HELPER_H
17#define DATA_STORAGE_RDB_SIM_HELPER_H
18
19#include <stdint.h>
20
21#include "iosfwd"
22#include "rdb_base_helper.h"
23#include "string"
24
25namespace OHOS {
26namespace Telephony {
27class RdbSimHelper : public RdbBaseHelper {
28public:
29    enum class SimCardType {
30        MAIN = 0, VOICE, MESSAGE, CELLULAR_DATA
31    };
32
33    RdbSimHelper();
34    ~RdbSimHelper() = default;
35
36    /**
37     * Update dataBase path
38     *
39     * @param path path
40     */
41    void UpdateDbPath(const std::string &path);
42
43    /**
44     * Clear sim_info table data
45     * @return 0 is succeed else failed
46     */
47    int32_t ClearData();
48
49    /**
50     * Init dataBase
51     *
52     * @return 0 is succeed else failed
53     */
54    int Init();
55
56    /**
57     * Set default card by card type
58     *
59     * @param simId  simId
60     * @param type card type
61     * @return 0 is succeed else failed
62     */
63    int32_t SetDefaultCardByType(int32_t simId, int32_t type);
64
65private:
66    /**
67     * Create SimInfo table
68     *
69     * @param createTableStr Create table statement
70     */
71    void CreateSimInfoTableStr(std::string &createTableStr);
72
73    /**
74     * Update sim_info table card state by card type
75     *
76     * @param type card type
77     * @param updateState Updated value that is 0 or 1
78     * @param whereSate Previous value
79     * @return 0 is succeed else failed
80     */
81    int32_t UpdateCardStateByType(int32_t type, int32_t updateState, int32_t whereSate);
82
83    /**
84     * Commit the transaction action
85     *
86     * @return 0 is succeed else failed
87     */
88    int CommitTransactionAction();
89
90private:
91    const std::string DB_NAME = "sim.db";
92    std::string dbPath_ = FOLDER_PATH + DB_NAME;
93    const int VERSION = 3;
94};
95} // namespace Telephony
96} // namespace OHOS
97#endif // DATA_STORAGE_RDB_SIM_HELPER_H