"use strict";
// SPDX-License-Identifier: Apache-2.0
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __metadata = (this && this.__metadata) || function (k, v) {
    if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.SecurityInPortSnapshot = void 0;
const LogErrorDecorator_1 = require("../../../../core/decorator/LogErrorDecorator");
const request_1 = require("../../request");
const BalancesOfAtSnapshotRequest_1 = __importDefault(require("../../../in/request/snapshots/BalancesOfAtSnapshotRequest"));
const ValidatedArgs_1 = __importDefault(require("../../../../core/validation/ValidatedArgs"));
const BaseSecurityInPort_1 = require("../BaseSecurityInPort");
const TakeSnapshotCommand_1 = require("../../../../app/usecase/command/security/operations/snapshot/takeSnapshot/TakeSnapshotCommand");
const GetTokenHoldersAtSnapshotQuery_1 = require("../../../../app/usecase/query/security/snapshot/getTokenHoldersAtSnapshot/GetTokenHoldersAtSnapshotQuery");
const GetTotalTokenHoldersAtSnapshotQuery_1 = require("../../../../app/usecase/query/security/snapshot/getTotalTokenHoldersAtSnapshot/GetTotalTokenHoldersAtSnapshotQuery");
const BalancesOfAtSnapshotQuery_1 = require("../../../../app/usecase/query/security/snapshot/balancesOfAtSnapshot/BalancesOfAtSnapshotQuery");
class SecurityInPortSnapshot extends BaseSecurityInPort_1.BaseSecurityInPort {
    async takeSnapshot(request) {
        const { securityId } = request;
        ValidatedArgs_1.default.handleValidation(request_1.TakeSnapshotRequest.name, request);
        return await this.commandBus.execute(new TakeSnapshotCommand_1.TakeSnapshotCommand(securityId));
    }
    async getTokenHoldersAtSnapshot(request) {
        const { securityId, snapshotId, start, end } = request;
        ValidatedArgs_1.default.handleValidation(request_1.GetTokenHoldersAtSnapshotRequest.name, request);
        return (await this.queryBus.execute(new GetTokenHoldersAtSnapshotQuery_1.GetTokenHoldersAtSnapshotQuery(securityId, snapshotId, start, end)))
            .payload;
    }
    async getTotalTokenHoldersAtSnapshot(request) {
        const { securityId, snapshotId } = request;
        ValidatedArgs_1.default.handleValidation(request_1.GetTotalTokenHoldersAtSnapshotRequest.name, request);
        return (await this.queryBus.execute(new GetTotalTokenHoldersAtSnapshotQuery_1.GetTotalTokenHoldersAtSnapshotQuery(securityId, snapshotId))).payload;
    }
    async balancesOfAtSnapshot(request) {
        const { securityId, snapshotId, pageIndex, pageLength } = request;
        ValidatedArgs_1.default.handleValidation(BalancesOfAtSnapshotRequest_1.default.name, request);
        return (await this.queryBus.execute(new BalancesOfAtSnapshotQuery_1.BalancesOfAtSnapshotQuery(securityId, snapshotId, pageIndex, pageLength)))
            .payload;
    }
}
exports.SecurityInPortSnapshot = SecurityInPortSnapshot;
__decorate([
    LogErrorDecorator_1.LogError,
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [request_1.TakeSnapshotRequest]),
    __metadata("design:returntype", Promise)
], SecurityInPortSnapshot.prototype, "takeSnapshot", null);
__decorate([
    LogErrorDecorator_1.LogError,
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [request_1.GetTokenHoldersAtSnapshotRequest]),
    __metadata("design:returntype", Promise)
], SecurityInPortSnapshot.prototype, "getTokenHoldersAtSnapshot", null);
__decorate([
    LogErrorDecorator_1.LogError,
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [request_1.GetTotalTokenHoldersAtSnapshotRequest]),
    __metadata("design:returntype", Promise)
], SecurityInPortSnapshot.prototype, "getTotalTokenHoldersAtSnapshot", null);
__decorate([
    LogErrorDecorator_1.LogError,
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [BalancesOfAtSnapshotRequest_1.default]),
    __metadata("design:returntype", Promise)
], SecurityInPortSnapshot.prototype, "balancesOfAtSnapshot", null);
