"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.SecurityInPortClearing = void 0;
const LogErrorDecorator_1 = require("../../../../core/decorator/LogErrorDecorator");
const request_1 = require("../../request");
const ValidatedArgs_1 = __importDefault(require("../../../../core/validation/ValidatedArgs"));
const ActivateClearingCommand_1 = require("../../../../app/usecase/command/security/operations/clearing/activateClearing/ActivateClearingCommand");
const DeactivateClearingCommand_1 = require("../../../../app/usecase/command/security/operations/clearing/deactivateClearing/DeactivateClearingCommand");
const ClearingTransferByPartitionCommand_1 = require("../../../../app/usecase/command/security/operations/clearing/clearingTransferByPartition/ClearingTransferByPartitionCommand");
const ClearingTransferFromByPartitionCommand_1 = require("../../../../app/usecase/command/security/operations/clearing/clearingTransferFromByPartition/ClearingTransferFromByPartitionCommand");
const ApproveClearingOperationByPartitionCommand_1 = require("../../../../app/usecase/command/security/operations/clearing/approveClearingOperationByPartition/ApproveClearingOperationByPartitionCommand");
const CancelClearingOperationByPartitionCommand_1 = require("../../../../app/usecase/command/security/operations/clearing/cancelClearingOperationByPartition/CancelClearingOperationByPartitionCommand");
const ReclaimClearingOperationByPartitionCommand_1 = require("../../../../app/usecase/command/security/operations/clearing/reclaimClearingOperationByPartition/ReclaimClearingOperationByPartitionCommand");
const ClearingRedeemByPartitionCommand_1 = require("../../../../app/usecase/command/security/operations/clearing/clearingRedeemByPartition/ClearingRedeemByPartitionCommand");
const ClearingRedeemFromByPartitionCommand_1 = require("../../../../app/usecase/command/security/operations/clearing/clearingRedeemFromByPartition/ClearingRedeemFromByPartitionCommand");
const ProtectedClearingRedeemByPartitionCommand_1 = require("../../../../app/usecase/command/security/operations/clearing/protectedClearingRedeemByPartition/ProtectedClearingRedeemByPartitionCommand");
const ClearingCreateHoldByPartitionCommand_1 = require("../../../../app/usecase/command/security/operations/clearing/clearingCreateHoldByPartition/ClearingCreateHoldByPartitionCommand");
const ClearingCreateHoldFromByPartitionCommand_1 = require("../../../../app/usecase/command/security/operations/clearing/clearingCreateHoldFromByPartition/ClearingCreateHoldFromByPartitionCommand");
const ProtectedClearingCreateHoldByPartitionCommand_1 = require("../../../../app/usecase/command/security/operations/clearing/protectedClearingCreateHoldByPartition/ProtectedClearingCreateHoldByPartitionCommand");
const GetClearedAmountForQuery_1 = require("../../../../app/usecase/query/security/clearing/getClearedAmountFor/GetClearedAmountForQuery");
const GetClearedAmountForByPartitionQuery_1 = require("../../../../app/usecase/query/security/clearing/getClearedAmountForByPartition/GetClearedAmountForByPartitionQuery");
const GetClearingCountForByPartitionQuery_1 = require("../../../../app/usecase/query/security/clearing/getClearingCountForByPartition/GetClearingCountForByPartitionQuery");
const GetClearingCreateHoldForByPartitionQuery_1 = require("../../../../app/usecase/query/security/clearing/getClearingCreateHoldForByPartition/GetClearingCreateHoldForByPartitionQuery");
const SecurityDate_1 = require("../../../../domain/context/shared/SecurityDate");
const GetClearingRedeemForByPartitionQuery_1 = require("../../../../app/usecase/query/security/clearing/getClearingRedeemForByPartition/GetClearingRedeemForByPartitionQuery");
const GetClearingTransferForByPartitionQuery_1 = require("../../../../app/usecase/query/security/clearing/getClearingTransferForByPartition/GetClearingTransferForByPartitionQuery");
const GetClearingsIdForByPartitionQuery_1 = require("../../../../app/usecase/query/security/clearing/getClearingsIdForByPartition/GetClearingsIdForByPartitionQuery");
const IsClearingActivatedQuery_1 = require("../../../../app/usecase/query/security/clearing/isClearingActivated/IsClearingActivatedQuery");
const OperatorClearingCreateHoldByPartitionCommand_1 = require("../../../../app/usecase/command/security/operations/clearing/operatorClearingCreateHoldByPartition/OperatorClearingCreateHoldByPartitionCommand");
const OperatorClearingRedeemByPartitionCommand_1 = require("../../../../app/usecase/command/security/operations/clearing/operatorClearingRedeemByPartition/OperatorClearingRedeemByPartitionCommand");
const OperatorClearingTransferByPartitionCommand_1 = require("../../../../app/usecase/command/security/operations/clearing/operatorClearingTransferByPartition/OperatorClearingTransferByPartitionCommand");
const ProtectedClearingTransferByPartitionCommand_1 = require("../../../../app/usecase/command/security/operations/clearing/protectedClearingTransferByPartition/ProtectedClearingTransferByPartitionCommand");
const BaseSecurityInPort_1 = require("../BaseSecurityInPort");
class SecurityInPortClearing extends BaseSecurityInPort_1.BaseSecurityInPort {
    async activateClearing(request) {
        ValidatedArgs_1.default.handleValidation("ActivateClearingRequest", request);
        return await this.commandBus.execute(new ActivateClearingCommand_1.ActivateClearingCommand(request.securityId));
    }
    async deactivateClearing(request) {
        ValidatedArgs_1.default.handleValidation("DeactivateClearingRequest", request);
        return await this.commandBus.execute(new DeactivateClearingCommand_1.DeactivateClearingCommand(request.securityId));
    }
    async clearingTransferByPartition(request) {
        ValidatedArgs_1.default.handleValidation("ClearingTransferByPartitionRequest", request);
        return await this.commandBus.execute(new ClearingTransferByPartitionCommand_1.ClearingTransferByPartitionCommand(request.securityId, request.partitionId, request.amount, request.targetId, request.expirationDate));
    }
    async clearingTransferFromByPartition(request) {
        ValidatedArgs_1.default.handleValidation("ClearingTransferFromByPartitionRequest", request);
        return await this.commandBus.execute(new ClearingTransferFromByPartitionCommand_1.ClearingTransferFromByPartitionCommand(request.securityId, request.partitionId, request.amount, request.sourceId, request.targetId, request.expirationDate));
    }
    async approveClearingOperationByPartition(request) {
        ValidatedArgs_1.default.handleValidation("ApproveClearingOperationByPartitionRequest", request);
        return await this.commandBus.execute(new ApproveClearingOperationByPartitionCommand_1.ApproveClearingOperationByPartitionCommand(request.securityId, request.partitionId, request.targetId, request.clearingId, request.clearingOperationType));
    }
    async cancelClearingOperationByPartition(request) {
        ValidatedArgs_1.default.handleValidation("CancelClearingOperationByPartitionRequest", request);
        return await this.commandBus.execute(new CancelClearingOperationByPartitionCommand_1.CancelClearingOperationByPartitionCommand(request.securityId, request.partitionId, request.targetId, request.clearingId, request.clearingOperationType));
    }
    async reclaimClearingOperationByPartition(request) {
        ValidatedArgs_1.default.handleValidation("ReclaimClearingOperationByPartitionRequest", request);
        return await this.commandBus.execute(new ReclaimClearingOperationByPartitionCommand_1.ReclaimClearingOperationByPartitionCommand(request.securityId, request.partitionId, request.targetId, request.clearingId, request.clearingOperationType));
    }
    async clearingRedeemByPartition(request) {
        ValidatedArgs_1.default.handleValidation("ClearingRedeemByPartitionRequest", request);
        return await this.commandBus.execute(new ClearingRedeemByPartitionCommand_1.ClearingRedeemByPartitionCommand(request.securityId, request.partitionId, request.amount, request.expirationDate));
    }
    async clearingRedeemFromByPartition(request) {
        ValidatedArgs_1.default.handleValidation("ClearingRedeemFromByPartitionRequest", request);
        return await this.commandBus.execute(new ClearingRedeemFromByPartitionCommand_1.ClearingRedeemFromByPartitionCommand(request.securityId, request.partitionId, request.amount, request.sourceId, request.expirationDate));
    }
    async protectedClearingRedeemByPartition(request) {
        ValidatedArgs_1.default.handleValidation("ProtectedClearingRedeemByPartitionRequest", request);
        return await this.commandBus.execute(new ProtectedClearingRedeemByPartitionCommand_1.ProtectedClearingRedeemByPartitionCommand(request.securityId, request.partitionId, request.amount, request.sourceId, request.expirationDate, request.deadline, request.nonce, request.signature));
    }
    async clearingCreateHoldByPartition(request) {
        ValidatedArgs_1.default.handleValidation("ClearingCreateHoldByPartitionRequest", request);
        return await this.commandBus.execute(new ClearingCreateHoldByPartitionCommand_1.ClearingCreateHoldByPartitionCommand(request.securityId, request.partitionId, request.escrowId, request.amount, request.targetId, request.clearingExpirationDate, request.holdExpirationDate));
    }
    async clearingCreateHoldFromByPartition(request) {
        ValidatedArgs_1.default.handleValidation("ClearingCreateHoldFromByPartitionRequest", request);
        return await this.commandBus.execute(new ClearingCreateHoldFromByPartitionCommand_1.ClearingCreateHoldFromByPartitionCommand(request.securityId, request.partitionId, request.escrowId, request.amount, request.sourceId, request.targetId, request.clearingExpirationDate, request.holdExpirationDate));
    }
    async protectedClearingCreateHoldByPartition(request) {
        ValidatedArgs_1.default.handleValidation("ProtectedClearingCreateHoldByPartitionRequest", request);
        return await this.commandBus.execute(new ProtectedClearingCreateHoldByPartitionCommand_1.ProtectedClearingCreateHoldByPartitionCommand(request.securityId, request.partitionId, request.escrowId, request.amount, request.sourceId, request.targetId, request.clearingExpirationDate, request.holdExpirationDate, request.deadline, request.nonce, request.signature));
    }
    async getClearedAmountFor(request) {
        ValidatedArgs_1.default.handleValidation("GetClearedAmountForByPartitionRequest", request);
        return (await this.queryBus.execute(new GetClearedAmountForQuery_1.GetClearedAmountForQuery(request.securityId, request.targetId))).payload;
    }
    async getClearedAmountForByPartition(request) {
        ValidatedArgs_1.default.handleValidation("GetClearedAmountForByPartitionRequest", request);
        return (await this.queryBus.execute(new GetClearedAmountForByPartitionQuery_1.GetClearedAmountForByPartitionQuery(request.securityId, request.partitionId, request.targetId))).payload;
    }
    async getClearingCountForByPartition(request) {
        ValidatedArgs_1.default.handleValidation("GetClearingCountForByPartitionRequest", request);
        return (await this.queryBus.execute(new GetClearingCountForByPartitionQuery_1.GetClearingCountForByPartitionQuery(request.securityId, request.partitionId, request.targetId, request.clearingOperationType))).payload;
    }
    async getClearingCreateHoldForByPartition(request) {
        ValidatedArgs_1.default.handleValidation("GetClearingCreateHoldForByPartitionRequest", request);
        const res = (await this.queryBus.execute(new GetClearingCreateHoldForByPartitionQuery_1.GetClearingCreateHoldForByPartitionQuery(request.securityId, request.partitionId, request.targetId, request.clearingId))).payload;
        const clearing = {
            id: request.clearingId,
            amount: res.amount.toString(),
            expirationDate: new Date(res.expirationTimestamp * SecurityDate_1.ONE_THOUSAND),
            data: res.data,
            operatorData: res.operatorData,
            holdEscrowId: res.holdEscrowId,
            holdExpirationDate: new Date(res.holdExpirationTimestamp * SecurityDate_1.ONE_THOUSAND),
            holdTo: res.holdTo,
            holdData: res.holdData,
        };
        return clearing;
    }
    async getClearingRedeemForByPartition(request) {
        ValidatedArgs_1.default.handleValidation("GetClearingRedeemForByPartitionRequest", request);
        const res = (await this.queryBus.execute(new GetClearingRedeemForByPartitionQuery_1.GetClearingRedeemForByPartitionQuery(request.securityId, request.partitionId, request.targetId, request.clearingId))).payload;
        const clearing = {
            id: request.clearingId,
            amount: res.amount.toString(),
            expirationDate: new Date(res.expirationTimestamp * SecurityDate_1.ONE_THOUSAND),
            data: res.data,
            operatorData: res.operatorData,
        };
        return clearing;
    }
    async getClearingTransferForByPartition(request) {
        ValidatedArgs_1.default.handleValidation("GetClearingTransferForByPartitionRequest", request);
        const res = (await this.queryBus.execute(new GetClearingTransferForByPartitionQuery_1.GetClearingTransferForByPartitionQuery(request.securityId, request.partitionId, request.targetId, request.clearingId))).payload;
        const clearing = {
            id: request.clearingId,
            amount: res.amount.toString(),
            expirationDate: new Date(res.expirationTimestamp * SecurityDate_1.ONE_THOUSAND),
            destination: res.destination,
            data: res.data,
            operatorData: res.operatorData,
        };
        return clearing;
    }
    async getClearingsIdForByPartition(request) {
        ValidatedArgs_1.default.handleValidation("GetClearingsIdForByPartitionRequest", request);
        return (await this.queryBus.execute(new GetClearingsIdForByPartitionQuery_1.GetClearingsIdForByPartitionQuery(request.securityId, request.partitionId, request.targetId, request.clearingOperationType, request.start, request.end))).payload;
    }
    async isClearingActivated(request) {
        ValidatedArgs_1.default.handleValidation("IsClearingActivatedRequest", request);
        return (await this.queryBus.execute(new IsClearingActivatedQuery_1.IsClearingActivatedQuery(request.securityId))).payload;
    }
    async operatorClearingCreateHoldByPartition(request) {
        ValidatedArgs_1.default.handleValidation("OperatorClearingCreateHoldByPartitionRequest", request);
        return await this.commandBus.execute(new OperatorClearingCreateHoldByPartitionCommand_1.OperatorClearingCreateHoldByPartitionCommand(request.securityId, request.partitionId, request.escrowId, request.amount, request.sourceId, request.targetId, request.clearingExpirationDate, request.holdExpirationDate));
    }
    async operatorClearingRedeemByPartition(request) {
        ValidatedArgs_1.default.handleValidation("OperatorClearingRedeemByPartitionRequest", request);
        return await this.commandBus.execute(new OperatorClearingRedeemByPartitionCommand_1.OperatorClearingRedeemByPartitionCommand(request.securityId, request.partitionId, request.amount, request.sourceId, request.expirationDate));
    }
    async operatorClearingTransferByPartition(request) {
        ValidatedArgs_1.default.handleValidation("OperatorClearingTransferByPartitionRequest", request);
        return await this.commandBus.execute(new OperatorClearingTransferByPartitionCommand_1.OperatorClearingTransferByPartitionCommand(request.securityId, request.partitionId, request.amount, request.sourceId, request.targetId, request.expirationDate));
    }
    async protectedClearingTransferByPartition(request) {
        ValidatedArgs_1.default.handleValidation("ProtectedClearingTransferByPartitionRequest", request);
        return await this.commandBus.execute(new ProtectedClearingTransferByPartitionCommand_1.ProtectedClearingTransferByPartitionCommand(request.securityId, request.partitionId, request.amount, request.sourceId, request.targetId, request.expirationDate, request.deadline, request.nonce, request.signature));
    }
}
exports.SecurityInPortClearing = SecurityInPortClearing;
__decorate([
    LogErrorDecorator_1.LogError,
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [request_1.ActivateClearingRequest]),
    __metadata("design:returntype", Promise)
], SecurityInPortClearing.prototype, "activateClearing", null);
__decorate([
    LogErrorDecorator_1.LogError,
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [request_1.DeactivateClearingRequest]),
    __metadata("design:returntype", Promise)
], SecurityInPortClearing.prototype, "deactivateClearing", null);
__decorate([
    LogErrorDecorator_1.LogError,
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [request_1.ClearingTransferByPartitionRequest]),
    __metadata("design:returntype", Promise)
], SecurityInPortClearing.prototype, "clearingTransferByPartition", null);
__decorate([
    LogErrorDecorator_1.LogError,
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [request_1.ClearingTransferFromByPartitionRequest]),
    __metadata("design:returntype", Promise)
], SecurityInPortClearing.prototype, "clearingTransferFromByPartition", null);
__decorate([
    LogErrorDecorator_1.LogError,
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [request_1.ApproveClearingOperationByPartitionRequest]),
    __metadata("design:returntype", Promise)
], SecurityInPortClearing.prototype, "approveClearingOperationByPartition", null);
__decorate([
    LogErrorDecorator_1.LogError,
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [request_1.CancelClearingOperationByPartitionRequest]),
    __metadata("design:returntype", Promise)
], SecurityInPortClearing.prototype, "cancelClearingOperationByPartition", null);
__decorate([
    LogErrorDecorator_1.LogError,
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [request_1.ReclaimClearingOperationByPartitionRequest]),
    __metadata("design:returntype", Promise)
], SecurityInPortClearing.prototype, "reclaimClearingOperationByPartition", null);
__decorate([
    LogErrorDecorator_1.LogError,
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [request_1.ClearingRedeemByPartitionRequest]),
    __metadata("design:returntype", Promise)
], SecurityInPortClearing.prototype, "clearingRedeemByPartition", null);
__decorate([
    LogErrorDecorator_1.LogError,
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [request_1.ClearingRedeemFromByPartitionRequest]),
    __metadata("design:returntype", Promise)
], SecurityInPortClearing.prototype, "clearingRedeemFromByPartition", null);
__decorate([
    LogErrorDecorator_1.LogError,
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [request_1.ProtectedClearingRedeemByPartitionRequest]),
    __metadata("design:returntype", Promise)
], SecurityInPortClearing.prototype, "protectedClearingRedeemByPartition", null);
__decorate([
    LogErrorDecorator_1.LogError,
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [request_1.ClearingCreateHoldByPartitionRequest]),
    __metadata("design:returntype", Promise)
], SecurityInPortClearing.prototype, "clearingCreateHoldByPartition", null);
__decorate([
    LogErrorDecorator_1.LogError,
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [request_1.ClearingCreateHoldFromByPartitionRequest]),
    __metadata("design:returntype", Promise)
], SecurityInPortClearing.prototype, "clearingCreateHoldFromByPartition", null);
__decorate([
    LogErrorDecorator_1.LogError,
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [request_1.ProtectedClearingCreateHoldByPartitionRequest]),
    __metadata("design:returntype", Promise)
], SecurityInPortClearing.prototype, "protectedClearingCreateHoldByPartition", null);
__decorate([
    LogErrorDecorator_1.LogError,
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [request_1.GetClearedAmountForRequest]),
    __metadata("design:returntype", Promise)
], SecurityInPortClearing.prototype, "getClearedAmountFor", null);
__decorate([
    LogErrorDecorator_1.LogError,
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [request_1.GetClearedAmountForByPartitionRequest]),
    __metadata("design:returntype", Promise)
], SecurityInPortClearing.prototype, "getClearedAmountForByPartition", null);
__decorate([
    LogErrorDecorator_1.LogError,
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [request_1.GetClearingCountForByPartitionRequest]),
    __metadata("design:returntype", Promise)
], SecurityInPortClearing.prototype, "getClearingCountForByPartition", null);
__decorate([
    LogErrorDecorator_1.LogError,
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [request_1.GetClearingCreateHoldForByPartitionRequest]),
    __metadata("design:returntype", Promise)
], SecurityInPortClearing.prototype, "getClearingCreateHoldForByPartition", null);
__decorate([
    LogErrorDecorator_1.LogError,
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [request_1.GetClearingRedeemForByPartitionRequest]),
    __metadata("design:returntype", Promise)
], SecurityInPortClearing.prototype, "getClearingRedeemForByPartition", null);
__decorate([
    LogErrorDecorator_1.LogError,
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [request_1.GetClearingTransferForByPartitionRequest]),
    __metadata("design:returntype", Promise)
], SecurityInPortClearing.prototype, "getClearingTransferForByPartition", null);
__decorate([
    LogErrorDecorator_1.LogError,
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [request_1.GetClearingsIdForByPartitionRequest]),
    __metadata("design:returntype", Promise)
], SecurityInPortClearing.prototype, "getClearingsIdForByPartition", null);
__decorate([
    LogErrorDecorator_1.LogError,
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [request_1.IsClearingActivatedRequest]),
    __metadata("design:returntype", Promise)
], SecurityInPortClearing.prototype, "isClearingActivated", null);
__decorate([
    LogErrorDecorator_1.LogError,
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [request_1.OperatorClearingCreateHoldByPartitionRequest]),
    __metadata("design:returntype", Promise)
], SecurityInPortClearing.prototype, "operatorClearingCreateHoldByPartition", null);
__decorate([
    LogErrorDecorator_1.LogError,
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [request_1.OperatorClearingRedeemByPartitionRequest]),
    __metadata("design:returntype", Promise)
], SecurityInPortClearing.prototype, "operatorClearingRedeemByPartition", null);
__decorate([
    LogErrorDecorator_1.LogError,
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [request_1.OperatorClearingTransferByPartitionRequest]),
    __metadata("design:returntype", Promise)
], SecurityInPortClearing.prototype, "operatorClearingTransferByPartition", null);
__decorate([
    LogErrorDecorator_1.LogError,
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [request_1.ProtectedClearingTransferByPartitionRequest]),
    __metadata("design:returntype", Promise)
], SecurityInPortClearing.prototype, "protectedClearingTransferByPartition", null);
