// 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 { ControllerCreateHoldByPartitionRequest, CreateHoldByPartitionRequest, CreateHoldFromByPartitionRequest, ExecuteHoldByPartitionRequest, GetHeldAmountForByPartitionRequest, GetHeldAmountForRequest, GetHoldCountForByPartitionRequest, GetHoldForByPartitionRequest, GetHoldsIdForByPartitionRequest, ProtectedCreateHoldByPartitionRequest, ReclaimHoldByPartitionRequest, ReleaseHoldByPartitionRequest, } from "../../request";
import ValidatedRequest from "../../../../core/validation/ValidatedArgs";
import { CreateHoldByPartitionCommand } from "../../../../app/usecase/command/security/operations/hold/createHoldByPartition/CreateHoldByPartitionCommand";
import { CreateHoldFromByPartitionCommand } from "../../../../app/usecase/command/security/operations/hold/createHoldFromByPartition/CreateHoldFromByPartitionCommand";
import { ControllerCreateHoldByPartitionCommand } from "../../../../app/usecase/command/security/operations/hold/controllerCreateHoldByPartition/ControllerCreateHoldByPartitionCommand";
import { ProtectedCreateHoldByPartitionCommand } from "../../../../app/usecase/command/security/operations/hold/protectedCreateHoldByPartition/ProtectedCreateHoldByPartitionCommand";
import { GetHeldAmountForQuery } from "../../../../app/usecase/query/security/hold/getHeldAmountFor/GetHeldAmountForQuery";
import { GetHeldAmountForByPartitionQuery } from "../../../../app/usecase/query/security/hold/getHeldAmountForByPartition/GetHeldAmountForByPartitionQuery";
import { GetHoldCountForByPartitionQuery } from "../../../../app/usecase/query/security/hold/getHoldCountForByPartition/GetHoldCountForByPartitionQuery";
import { GetHoldsIdForByPartitionQuery } from "../../../../app/usecase/query/security/hold/getHoldsIdForByPartition/GetHoldsIdForByPartitionQuery";
import { GetHoldForByPartitionQuery } from "../../../../app/usecase/query/security/hold/getHoldForByPartition/GetHoldForByPartitionQuery";
import { ONE_THOUSAND } from "../../../../domain/context/shared/SecurityDate";
import { ReleaseHoldByPartitionCommand } from "../../../../app/usecase/command/security/operations/hold/releaseHoldByPartition/ReleaseHoldByPartitionCommand";
import { ReclaimHoldByPartitionCommand } from "../../../../app/usecase/command/security/operations/hold/reclaimHoldByPartition/ReclaimHoldByPartitionCommand";
import { ExecuteHoldByPartitionCommand } from "../../../../app/usecase/command/security/operations/hold/executeHoldByPartition/ExecuteHoldByPartitionCommand";
import { BaseSecurityInPort } from "../BaseSecurityInPort";
export class SecurityInPortHold extends BaseSecurityInPort {
    async createHoldByPartition(request) {
        const { securityId, partitionId, amount, escrowId, targetId, expirationDate } = request;
        ValidatedRequest.handleValidation("CreateHoldByPartitionRequest", request);
        return await this.commandBus.execute(new CreateHoldByPartitionCommand(securityId, partitionId, escrowId, amount, targetId, expirationDate));
    }
    async createHoldFromByPartition(request) {
        const { securityId, partitionId, amount, escrowId, sourceId, targetId, expirationDate } = request;
        ValidatedRequest.handleValidation("CreateHoldFromByPartitionRequest", request);
        return await this.commandBus.execute(new CreateHoldFromByPartitionCommand(securityId, partitionId, escrowId, amount, sourceId, targetId, expirationDate));
    }
    async controllerCreateHoldByPartition(request) {
        const { securityId, partitionId, amount, escrowId, sourceId, targetId, expirationDate } = request;
        ValidatedRequest.handleValidation("ControllerCreateHoldByPartitionRequest", request);
        return await this.commandBus.execute(new ControllerCreateHoldByPartitionCommand(securityId, partitionId, escrowId, amount, sourceId, targetId, expirationDate));
    }
    async protectedCreateHoldByPartition(request) {
        const { securityId, partitionId, amount, escrowId, sourceId, targetId, expirationDate, deadline, nonce, signature, } = request;
        ValidatedRequest.handleValidation("ProtectedCreateHoldByPartitionRequest", request);
        return await this.commandBus.execute(new ProtectedCreateHoldByPartitionCommand(securityId, partitionId, escrowId, amount, sourceId, targetId, expirationDate, deadline, nonce, signature));
    }
    async getHeldAmountFor(request) {
        ValidatedRequest.handleValidation("GetHeldAmountForRequest", request);
        return (await this.queryBus.execute(new GetHeldAmountForQuery(request.securityId, request.targetId))).payload;
    }
    async getHeldAmountForByPartition(request) {
        ValidatedRequest.handleValidation("GetHeldAmountForByPartitionRequest", request);
        return (await this.queryBus.execute(new GetHeldAmountForByPartitionQuery(request.securityId, request.partitionId, request.targetId))).payload;
    }
    async getHoldCountForByPartition(request) {
        ValidatedRequest.handleValidation("GetHoldCountForByPartitionRequest", request);
        return (await this.queryBus.execute(new GetHoldCountForByPartitionQuery(request.securityId, request.partitionId, request.targetId))).payload;
    }
    async getHoldsIdForByPartition(request) {
        ValidatedRequest.handleValidation("GetHoldsIdForByPartitionRequest", request);
        return (await this.queryBus.execute(new GetHoldsIdForByPartitionQuery(request.securityId, request.partitionId, request.targetId, request.start, request.end))).payload;
    }
    async getHoldForByPartition(request) {
        ValidatedRequest.handleValidation("GetHoldForByPartitionRequest", request);
        const res = (await this.queryBus.execute(new GetHoldForByPartitionQuery(request.securityId, request.partitionId, request.targetId, request.holdId))).payload;
        const hold = {
            id: request.holdId,
            amount: res.amount.toString(),
            expirationDate: new Date(res.expirationTimeStamp * 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;
        ValidatedRequest.handleValidation("ReleaseHoldByPartitionRequest", request);
        return await this.commandBus.execute(new ReleaseHoldByPartitionCommand(securityId, partitionId, amount, holdId, targetId));
    }
    async reclaimHoldByPartition(request) {
        const { securityId, partitionId, targetId, holdId } = request;
        ValidatedRequest.handleValidation("ReclaimHoldByPartitionRequest", request);
        return await this.commandBus.execute(new ReclaimHoldByPartitionCommand(securityId, partitionId, holdId, targetId));
    }
    async executeHoldByPartition(request) {
        const { securityId, sourceId, amount, holdId, targetId, partitionId } = request;
        ValidatedRequest.handleValidation("ExecuteHoldByPartitionRequest", request);
        return await this.commandBus.execute(new ExecuteHoldByPartitionCommand(securityId, sourceId, amount, holdId, targetId, partitionId));
    }
}
__decorate([
    LogError,
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [CreateHoldByPartitionRequest]),
    __metadata("design:returntype", Promise)
], SecurityInPortHold.prototype, "createHoldByPartition", null);
__decorate([
    LogError,
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [CreateHoldFromByPartitionRequest]),
    __metadata("design:returntype", Promise)
], SecurityInPortHold.prototype, "createHoldFromByPartition", null);
__decorate([
    LogError,
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [ControllerCreateHoldByPartitionRequest]),
    __metadata("design:returntype", Promise)
], SecurityInPortHold.prototype, "controllerCreateHoldByPartition", null);
__decorate([
    LogError,
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [ProtectedCreateHoldByPartitionRequest]),
    __metadata("design:returntype", Promise)
], SecurityInPortHold.prototype, "protectedCreateHoldByPartition", null);
__decorate([
    LogError,
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [GetHeldAmountForRequest]),
    __metadata("design:returntype", Promise)
], SecurityInPortHold.prototype, "getHeldAmountFor", null);
__decorate([
    LogError,
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [GetHeldAmountForByPartitionRequest]),
    __metadata("design:returntype", Promise)
], SecurityInPortHold.prototype, "getHeldAmountForByPartition", null);
__decorate([
    LogError,
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [GetHoldCountForByPartitionRequest]),
    __metadata("design:returntype", Promise)
], SecurityInPortHold.prototype, "getHoldCountForByPartition", null);
__decorate([
    LogError,
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [GetHoldsIdForByPartitionRequest]),
    __metadata("design:returntype", Promise)
], SecurityInPortHold.prototype, "getHoldsIdForByPartition", null);
__decorate([
    LogError,
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [GetHoldForByPartitionRequest]),
    __metadata("design:returntype", Promise)
], SecurityInPortHold.prototype, "getHoldForByPartition", null);
__decorate([
    LogError,
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [ReleaseHoldByPartitionRequest]),
    __metadata("design:returntype", Promise)
], SecurityInPortHold.prototype, "releaseHoldByPartition", null);
__decorate([
    LogError,
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [ReclaimHoldByPartitionRequest]),
    __metadata("design:returntype", Promise)
], SecurityInPortHold.prototype, "reclaimHoldByPartition", null);
__decorate([
    LogError,
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [ExecuteHoldByPartitionRequest]),
    __metadata("design:returntype", Promise)
], SecurityInPortHold.prototype, "executeHoldByPartition", null);
