"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.SecurityInPortHold = void 0;
const LogErrorDecorator_1 = require("../../../../core/decorator/LogErrorDecorator");
const request_1 = require("../../request");
const ValidatedArgs_1 = __importDefault(require("../../../../core/validation/ValidatedArgs"));
const CreateHoldByPartitionCommand_1 = require("../../../../app/usecase/command/security/operations/hold/createHoldByPartition/CreateHoldByPartitionCommand");
const CreateHoldFromByPartitionCommand_1 = require("../../../../app/usecase/command/security/operations/hold/createHoldFromByPartition/CreateHoldFromByPartitionCommand");
const ControllerCreateHoldByPartitionCommand_1 = require("../../../../app/usecase/command/security/operations/hold/controllerCreateHoldByPartition/ControllerCreateHoldByPartitionCommand");
const ProtectedCreateHoldByPartitionCommand_1 = require("../../../../app/usecase/command/security/operations/hold/protectedCreateHoldByPartition/ProtectedCreateHoldByPartitionCommand");
const GetHeldAmountForQuery_1 = require("../../../../app/usecase/query/security/hold/getHeldAmountFor/GetHeldAmountForQuery");
const GetHeldAmountForByPartitionQuery_1 = require("../../../../app/usecase/query/security/hold/getHeldAmountForByPartition/GetHeldAmountForByPartitionQuery");
const GetHoldCountForByPartitionQuery_1 = require("../../../../app/usecase/query/security/hold/getHoldCountForByPartition/GetHoldCountForByPartitionQuery");
const GetHoldsIdForByPartitionQuery_1 = require("../../../../app/usecase/query/security/hold/getHoldsIdForByPartition/GetHoldsIdForByPartitionQuery");
const GetHoldForByPartitionQuery_1 = require("../../../../app/usecase/query/security/hold/getHoldForByPartition/GetHoldForByPartitionQuery");
const SecurityDate_1 = require("../../../../domain/context/shared/SecurityDate");
const ReleaseHoldByPartitionCommand_1 = require("../../../../app/usecase/command/security/operations/hold/releaseHoldByPartition/ReleaseHoldByPartitionCommand");
const ReclaimHoldByPartitionCommand_1 = require("../../../../app/usecase/command/security/operations/hold/reclaimHoldByPartition/ReclaimHoldByPartitionCommand");
const ExecuteHoldByPartitionCommand_1 = require("../../../../app/usecase/command/security/operations/hold/executeHoldByPartition/ExecuteHoldByPartitionCommand");
const BaseSecurityInPort_1 = require("../BaseSecurityInPort");
class SecurityInPortHold extends BaseSecurityInPort_1.BaseSecurityInPort {
    async createHoldByPartition(request) {
        const { securityId, partitionId, amount, escrowId, targetId, expirationDate } = request;
        ValidatedArgs_1.default.handleValidation("CreateHoldByPartitionRequest", request);
        return await this.commandBus.execute(new CreateHoldByPartitionCommand_1.CreateHoldByPartitionCommand(securityId, partitionId, escrowId, amount, targetId, expirationDate));
    }
    async createHoldFromByPartition(request) {
        const { securityId, partitionId, amount, escrowId, sourceId, targetId, expirationDate } = request;
        ValidatedArgs_1.default.handleValidation("CreateHoldFromByPartitionRequest", request);
        return await this.commandBus.execute(new CreateHoldFromByPartitionCommand_1.CreateHoldFromByPartitionCommand(securityId, partitionId, escrowId, amount, sourceId, targetId, expirationDate));
    }
    async controllerCreateHoldByPartition(request) {
        const { securityId, partitionId, amount, escrowId, sourceId, targetId, expirationDate } = request;
        ValidatedArgs_1.default.handleValidation("ControllerCreateHoldByPartitionRequest", request);
        return await this.commandBus.execute(new ControllerCreateHoldByPartitionCommand_1.ControllerCreateHoldByPartitionCommand(securityId, partitionId, escrowId, amount, sourceId, targetId, expirationDate));
    }
    async protectedCreateHoldByPartition(request) {
        const { securityId, partitionId, amount, escrowId, sourceId, targetId, expirationDate, deadline, nonce, signature, } = request;
        ValidatedArgs_1.default.handleValidation("ProtectedCreateHoldByPartitionRequest", request);
        return await this.commandBus.execute(new ProtectedCreateHoldByPartitionCommand_1.ProtectedCreateHoldByPartitionCommand(securityId, partitionId, escrowId, amount, sourceId, targetId, expirationDate, deadline, nonce, signature));
    }
    async getHeldAmountFor(request) {
        ValidatedArgs_1.default.handleValidation("GetHeldAmountForRequest", request);
        return (await this.queryBus.execute(new GetHeldAmountForQuery_1.GetHeldAmountForQuery(request.securityId, request.targetId))).payload;
    }
    async getHeldAmountForByPartition(request) {
        ValidatedArgs_1.default.handleValidation("GetHeldAmountForByPartitionRequest", request);
        return (await this.queryBus.execute(new GetHeldAmountForByPartitionQuery_1.GetHeldAmountForByPartitionQuery(request.securityId, request.partitionId, request.targetId))).payload;
    }
    async getHoldCountForByPartition(request) {
        ValidatedArgs_1.default.handleValidation("GetHoldCountForByPartitionRequest", request);
        return (await this.queryBus.execute(new GetHoldCountForByPartitionQuery_1.GetHoldCountForByPartitionQuery(request.securityId, request.partitionId, request.targetId))).payload;
    }
    async getHoldsIdForByPartition(request) {
        ValidatedArgs_1.default.handleValidation("GetHoldsIdForByPartitionRequest", request);
        return (await this.queryBus.execute(new GetHoldsIdForByPartitionQuery_1.GetHoldsIdForByPartitionQuery(request.securityId, request.partitionId, request.targetId, request.start, request.end))).payload;
    }
    async getHoldForByPartition(request) {
        ValidatedArgs_1.default.handleValidation("GetHoldForByPartitionRequest", request);
        const res = (await this.queryBus.execute(new GetHoldForByPartitionQuery_1.GetHoldForByPartitionQuery(request.securityId, request.partitionId, request.targetId, request.holdId))).payload;
        const hold = {
            id: request.holdId,
            amount: res.amount.toString(),
            expirationDate: new Date(res.expirationTimeStamp * SecurityDate_1.ONE_THOUSAND),
            tokenHolderAddress: res.tokenHolderAddress,
            escrowAddress: res.escrowAddress,
            destinationAddress: res.destinationAddress,
            data: res.data,
            operatorData: res.operatorData,
        };
        return hold;
    }
    async releaseHoldByPartition(request) {
        const { securityId, partitionId, amount, targetId, holdId } = request;
        ValidatedArgs_1.default.handleValidation("ReleaseHoldByPartitionRequest", request);
        return await this.commandBus.execute(new ReleaseHoldByPartitionCommand_1.ReleaseHoldByPartitionCommand(securityId, partitionId, amount, holdId, targetId));
    }
    async reclaimHoldByPartition(request) {
        const { securityId, partitionId, targetId, holdId } = request;
        ValidatedArgs_1.default.handleValidation("ReclaimHoldByPartitionRequest", request);
        return await this.commandBus.execute(new ReclaimHoldByPartitionCommand_1.ReclaimHoldByPartitionCommand(securityId, partitionId, holdId, targetId));
    }
    async executeHoldByPartition(request) {
        const { securityId, sourceId, amount, holdId, targetId, partitionId } = request;
        ValidatedArgs_1.default.handleValidation("ExecuteHoldByPartitionRequest", request);
        return await this.commandBus.execute(new ExecuteHoldByPartitionCommand_1.ExecuteHoldByPartitionCommand(securityId, sourceId, amount, holdId, targetId, partitionId));
    }
}
exports.SecurityInPortHold = SecurityInPortHold;
__decorate([
    LogErrorDecorator_1.LogError,
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [request_1.CreateHoldByPartitionRequest]),
    __metadata("design:returntype", Promise)
], SecurityInPortHold.prototype, "createHoldByPartition", null);
__decorate([
    LogErrorDecorator_1.LogError,
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [request_1.CreateHoldFromByPartitionRequest]),
    __metadata("design:returntype", Promise)
], SecurityInPortHold.prototype, "createHoldFromByPartition", null);
__decorate([
    LogErrorDecorator_1.LogError,
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [request_1.ControllerCreateHoldByPartitionRequest]),
    __metadata("design:returntype", Promise)
], SecurityInPortHold.prototype, "controllerCreateHoldByPartition", null);
__decorate([
    LogErrorDecorator_1.LogError,
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [request_1.ProtectedCreateHoldByPartitionRequest]),
    __metadata("design:returntype", Promise)
], SecurityInPortHold.prototype, "protectedCreateHoldByPartition", null);
__decorate([
    LogErrorDecorator_1.LogError,
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [request_1.GetHeldAmountForRequest]),
    __metadata("design:returntype", Promise)
], SecurityInPortHold.prototype, "getHeldAmountFor", null);
__decorate([
    LogErrorDecorator_1.LogError,
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [request_1.GetHeldAmountForByPartitionRequest]),
    __metadata("design:returntype", Promise)
], SecurityInPortHold.prototype, "getHeldAmountForByPartition", null);
__decorate([
    LogErrorDecorator_1.LogError,
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [request_1.GetHoldCountForByPartitionRequest]),
    __metadata("design:returntype", Promise)
], SecurityInPortHold.prototype, "getHoldCountForByPartition", null);
__decorate([
    LogErrorDecorator_1.LogError,
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [request_1.GetHoldsIdForByPartitionRequest]),
    __metadata("design:returntype", Promise)
], SecurityInPortHold.prototype, "getHoldsIdForByPartition", null);
__decorate([
    LogErrorDecorator_1.LogError,
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [request_1.GetHoldForByPartitionRequest]),
    __metadata("design:returntype", Promise)
], SecurityInPortHold.prototype, "getHoldForByPartition", null);
__decorate([
    LogErrorDecorator_1.LogError,
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [request_1.ReleaseHoldByPartitionRequest]),
    __metadata("design:returntype", Promise)
], SecurityInPortHold.prototype, "releaseHoldByPartition", null);
__decorate([
    LogErrorDecorator_1.LogError,
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [request_1.ReclaimHoldByPartitionRequest]),
    __metadata("design:returntype", Promise)
], SecurityInPortHold.prototype, "reclaimHoldByPartition", null);
__decorate([
    LogErrorDecorator_1.LogError,
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [request_1.ExecuteHoldByPartitionRequest]),
    __metadata("design:returntype", Promise)
], SecurityInPortHold.prototype, "executeHoldByPartition", null);
