#pragma once
#include "../db/pool.hpp"
#include "nlohmann/json.hpp"

inline nlohmann::json get_deleted_entity_list(int64_t cursor, int limit) {
    std::string sql =
        "SELECT TOP (?) vDeletedEntity.kEntityId, "
        "vDeletedEntity.nEntityType, "
        "CONVERT(BIGINT, vDeletedEntity.bLastChanged) AS lastChanged "
        "FROM Pos.vDeletedEntity "
        "WHERE CONVERT(BIGINT, vDeletedEntity.bLastChanged) > ? "
        "ORDER BY lastChanged ASC";
    std::vector<Param> ps = {
        {ParamType::Int,"",limit},
        {ParamType::BigInt,"",cursor}
    };
    ResultSet rs;
    get_pool().execute(sql, ps, rs);
    nlohmann::json result = nlohmann::json::array();
    for (auto& row : rs) {
        result.push_back({
            {"entityId", row[0].str},
            {"entityType", row[1].str},
            {"lastChanged", row[2].str}
        });
    }
    return result;
}
