// Copyright (c) 2017-2022, Mudita Sp. z.o.o. All rights reserved. // For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md #pragma once #include "Common/Common.hpp" #include "ContactRecord.hpp" #include "module-db/databases/CalllogDB.hpp" #include "Record.hpp" #include "queries/calllog/QueryCalllogSetAllRead.hpp" #include #include #include #include struct CalllogRecord : public Record { PresentationType presentation = PresentationType::PR_UNKNOWN; time_t date = 0; time_t duration = 0; CallType type = CallType::CT_NONE; UTF8 name = ""; utils::PhoneNumber::View phoneNumber = utils::PhoneNumber::View(); bool isRead = true; friend std::ostream &operator<<(std::ostream &out, const CalllogRecord &point); [[nodiscard]] std::string str() const; CalllogRecord() = default; CalllogRecord(const CalllogRecord &rhs); CalllogRecord(const CallType type, const utils::PhoneNumber::View &number); CalllogRecord(const CalllogTableRow &tableRow); CalllogRecord &operator=(const CalllogRecord &); }; enum class CalllogRecordField { DATE, TYPE, }; class CalllogRecordInterface : public RecordInterface { public: CalllogRecordInterface(CalllogDB *CalllogDb, ContactsDB *contactsDb); bool Add(const CalllogRecord &rec) override final; bool RemoveByID(uint32_t id) override final; bool RemoveByField(CalllogRecordField field, const char *str) override final; bool Update(const CalllogRecord &rec) override final; CalllogRecord GetByID(uint32_t id) override final; uint32_t GetCount() override final; uint32_t GetCount(EntryState state); bool SetAllRead(); bool DeleteAll(); std::unique_ptr> GetLimitOffset(uint32_t offset, uint32_t limit) override final; std::unique_ptr> GetLimitOffsetByField(uint32_t offset, uint32_t limit, CalllogRecordField field, const char *str) override final; uint32_t GetLastID(); std::unique_ptr runQuery(std::shared_ptr query) override; private: CalllogDB *calllogDB = nullptr; ContactsDB *contactsDB = nullptr; std::vector GetByContactID(uint32_t id); std::unique_ptr getQuery(std::shared_ptr query); std::unique_ptr setAllReadQuery(std::shared_ptr query); std::unique_ptr deleteAllQuery(std::shared_ptr query); std::unique_ptr getCountQuery(std::shared_ptr query); std::unique_ptr removeQuery(std::shared_ptr query); std::unique_ptr getByContactIDQuery(std::shared_ptr query); std::optional getContactByNumber(utils::PhoneNumber::View number); };