"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.SecurityInPortTransfer = void 0;
const LogErrorDecorator_1 = require("../../../../core/decorator/LogErrorDecorator");
const request_1 = require("../../request");
const ValidatedArgs_1 = __importDefault(require("../../../../core/validation/ValidatedArgs"));
const TransferCommand_1 = require("../../../../app/usecase/command/security/operations/transfer/TransferCommand");
const TransferAndLockCommand_1 = require("../../../../app/usecase/command/security/operations/transfer/TransferAndLockCommand");
const ControllerTransferCommand_1 = require("../../../../app/usecase/command/security/operations/transfer/ControllerTransferCommand");
const ForcedTransferCommand_1 = require("../../../../app/usecase/command/security/operations/transfer/ForcedTransferCommand");
const BatchTransferCommand_1 = require("../../../../app/usecase/command/security/operations/batch/batchTransfer/BatchTransferCommand");
const BatchForcedTransferCommand_1 = require("../../../../app/usecase/command/security/operations/batch/batchForcedTransfer/BatchForcedTransferCommand");
const ProtectedTransferFromByPartitionCommand_1 = require("../../../../app/usecase/command/security/operations/transfer/ProtectedTransferFromByPartitionCommand");
const BaseSecurityInPort_1 = require("../BaseSecurityInPort");
class SecurityInPortTransfer extends BaseSecurityInPort_1.BaseSecurityInPort {
    async transfer(request) {
        const { securityId, amount, targetId } = request;
        ValidatedArgs_1.default.handleValidation("TransferRequest", request);
        return await this.commandBus.execute(new TransferCommand_1.TransferCommand(amount, targetId, securityId));
    }
    async transferAndLock(request) {
        const { securityId, amount, targetId, expirationDate } = request;
        ValidatedArgs_1.default.handleValidation("TransferAndLockRequest", request);
        return await this.commandBus.execute(new TransferAndLockCommand_1.TransferAndLockCommand(amount, targetId, securityId, expirationDate));
    }
    async controllerTransfer(request) {
        const { securityId, amount, targetId, sourceId } = request;
        ValidatedArgs_1.default.handleValidation("ForceTransferRequest", request);
        return await this.commandBus.execute(new ControllerTransferCommand_1.ControllerTransferCommand(amount, sourceId, targetId, securityId));
    }
    async forcedTransfer(request) {
        const { securityId, amount, targetId, sourceId } = request;
        ValidatedArgs_1.default.handleValidation("ForcedTransferRequest", request);
        return await this.commandBus.execute(new ForcedTransferCommand_1.ForcedTransferCommand(sourceId, targetId, amount, securityId));
    }
    async batchTransfer(request) {
        ValidatedArgs_1.default.handleValidation("BatchTransferRequest", request);
        return await this.commandBus.execute(new BatchTransferCommand_1.BatchTransferCommand(request.securityId, request.amountList, request.toList));
    }
    async batchForcedTransfer(request) {
        ValidatedArgs_1.default.handleValidation("BatchForcedTransferRequest", request);
        return await this.commandBus.execute(new BatchForcedTransferCommand_1.BatchForcedTransferCommand(request.securityId, request.amountList, request.fromList, request.toList));
    }
    async protectedTransferFromByPartition(request) {
        const { securityId, partitionId, sourceId, targetId, amount, deadline, nounce, signature } = request;
        ValidatedArgs_1.default.handleValidation("ProtectedTransferFromByPartitionRequest", request);
        return await this.commandBus.execute(new ProtectedTransferFromByPartitionCommand_1.ProtectedTransferFromByPartitionCommand(securityId, partitionId, sourceId, targetId, amount, deadline, nounce, signature));
    }
}
exports.SecurityInPortTransfer = SecurityInPortTransfer;
__decorate([
    LogErrorDecorator_1.LogError,
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [request_1.TransferRequest]),
    __metadata("design:returntype", Promise)
], SecurityInPortTransfer.prototype, "transfer", null);
__decorate([
    LogErrorDecorator_1.LogError,
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [request_1.TransferAndLockRequest]),
    __metadata("design:returntype", Promise)
], SecurityInPortTransfer.prototype, "transferAndLock", null);
__decorate([
    LogErrorDecorator_1.LogError,
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [request_1.ForceTransferRequest]),
    __metadata("design:returntype", Promise)
], SecurityInPortTransfer.prototype, "controllerTransfer", null);
__decorate([
    LogErrorDecorator_1.LogError,
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [request_1.ForcedTransferRequest]),
    __metadata("design:returntype", Promise)
], SecurityInPortTransfer.prototype, "forcedTransfer", null);
__decorate([
    LogErrorDecorator_1.LogError,
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [request_1.BatchTransferRequest]),
    __metadata("design:returntype", Promise)
], SecurityInPortTransfer.prototype, "batchTransfer", null);
__decorate([
    LogErrorDecorator_1.LogError,
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [request_1.BatchForcedTransferRequest]),
    __metadata("design:returntype", Promise)
], SecurityInPortTransfer.prototype, "batchForcedTransfer", null);
__decorate([
    LogErrorDecorator_1.LogError,
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [request_1.ProtectedTransferFromByPartitionRequest]),
    __metadata("design:returntype", Promise)
], SecurityInPortTransfer.prototype, "protectedTransferFromByPartition", null);
