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