1 /*
2  * Copyright (C) 2024-2025 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 #ifndef OHOS_MEDIA_BACKUP_EXTERNAL_FILES_COUNT_STATISTIC_H
16 #define OHOS_MEDIA_BACKUP_EXTERNAL_FILES_COUNT_STATISTIC_H
17 
18 #include <string>
19 #include <vector>
20 
21 #include "rdb_store.h"
22 #include "result_set_utils.h"
23 #include "media_backup_report_data_type.h"
24 
25 namespace OHOS::Media {
26 class ExternalFilesCountStatistic {
27 public:
SetExternalRdb(std::shared_ptr<NativeRdb::RdbStore> externalRdb)28     ExternalFilesCountStatistic &SetExternalRdb(std::shared_ptr<NativeRdb::RdbStore> externalRdb)
29     {
30         this->externalRdb_ = externalRdb;
31         return *this;
32     }
SetGalleryRdb(std::shared_ptr<NativeRdb::RdbStore> galleryRdb)33     ExternalFilesCountStatistic &SetGalleryRdb(std::shared_ptr<NativeRdb::RdbStore> galleryRdb)
34     {
35         this->galleryRdb_ = galleryRdb;
36         return *this;
37     }
SetSceneCode(int32_t sceneCode)38     ExternalFilesCountStatistic &SetSceneCode(int32_t sceneCode)
39     {
40         this->sceneCode_ = sceneCode;
41         return *this;
42     }
SetTaskId(const std::string & taskId)43     ExternalFilesCountStatistic &SetTaskId(const std::string &taskId)
44     {
45         this->taskId_ = taskId;
46         return *this;
47     }
48     std::vector<AlbumMediaStatisticInfo> Load();
49 
50 private:
51     int32_t QueryExternalAudioCount();
52     std::unordered_map<int32_t, int32_t> QueryExternalImageAndVideoCount();
53     std::unordered_map<int32_t, int32_t> QueryGalleryNotSyncMedia(const int32_t maxId);
54     AlbumMediaStatisticInfo GetMediaStatInfo();
55     AlbumMediaStatisticInfo GetAudioStatInfo();
56     AlbumMediaStatisticInfo GetGalleryNotSyncMediaStatInfo();
57     void GetMediaStatInfoFromMap(const std::unordered_map<int32_t, int32_t>& mediaTypeCountMap,
58         AlbumMediaStatisticInfo& info);
59 private:
60     std::shared_ptr<NativeRdb::RdbStore> externalRdb_;
61     std::shared_ptr<NativeRdb::RdbStore> galleryRdb_;
62     int32_t sceneCode_;
63     std::string taskId_;
64 };
65 }  // namespace OHOS::Media
66 #endif  // OHOS_MEDIA_BACKUP_EXTERNAL_FILES_COUNT_STATISTIC_H