// 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 __param = (this && this.__param) || function (paramIndex, decorator) {
    return function (target, key) { decorator(target, key, paramIndex); }
};
/* eslint-disable @typescript-eslint/no-unused-vars */
import UpdateConfigVersionRequest from "../request/management/UpdateConfigVersionRequest";
import { LogError } from "../../../core/decorator/LogErrorDecorator";
import ValidatedRequest from "../../../core/validation/ValidatedArgs";
import { UpdateConfigVersionCommand } from "../../../app/usecase/command/management/updateConfigVersion/updateConfigVersionCommand";
import { QueryBus } from "../../../core/query/QueryBus";
import Injectable from "../../../core/injectable/Injectable";
import { CommandBus } from "../../../core/command/CommandBus";
import { GetConfigInfoRequest } from "../request";
import UpdateResolverRequest from "../request/management/UpdateResolverRequest";
import { UpdateResolverCommand } from "../../../app/usecase/command/management/updateResolver/updateResolverCommand";
import ContractId from "../../../domain/context/contract/ContractId";
import { GetConfigInfoQuery } from "../../../app/usecase/query/management/GetConfigInfoQuery";
import { lazyInject } from "../../../core/decorator/LazyInjectDecorator";
import { UpdateConfigRequest } from "../request";
import { UpdateConfigCommand } from "../../../app/usecase/command/management/updateConfig/updateConfigCommand";
import { MirrorNodeAdapter } from "../../out/mirror/MirrorNodeAdapter";
let ManagementInPort = class ManagementInPort {
    commandBus;
    queryBus;
    mirrorNode;
    constructor(commandBus = Injectable.resolve(CommandBus), queryBus = Injectable.resolve(QueryBus), mirrorNode = Injectable.resolve(MirrorNodeAdapter)) {
        this.commandBus = commandBus;
        this.queryBus = queryBus;
        this.mirrorNode = mirrorNode;
    }
    async updateConfigVersion(request) {
        const { configVersion, securityId } = request;
        ValidatedRequest.handleValidation("UpdateConfigVersionRequest", request);
        return await this.commandBus.execute(new UpdateConfigVersionCommand(configVersion, securityId));
    }
    async updateConfig(request) {
        const { configId, configVersion, securityId } = request;
        ValidatedRequest.handleValidation("UpdateConfigRequest", request);
        return await this.commandBus.execute(new UpdateConfigCommand(configId, configVersion, securityId));
    }
    async updateResolver(request) {
        const { configId, securityId, resolver, configVersion } = request;
        ValidatedRequest.handleValidation("UpdateResolverRequest", request);
        return await this.commandBus.execute(new UpdateResolverCommand(configVersion, securityId, configId, new ContractId(resolver)));
    }
    async getConfigInfo(request) {
        ValidatedRequest.handleValidation("GetConfigInfoRequest", request);
        const { payload } = await this.queryBus.execute(new GetConfigInfoQuery(request.securityId));
        const { resolverAddress, configId, configVersion } = payload;
        const resolverId = (await this.mirrorNode.getContractInfo(resolverAddress)).id;
        return {
            resolverAddress: resolverId,
            configId,
            configVersion,
        };
    }
};
__decorate([
    LogError,
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [UpdateConfigVersionRequest]),
    __metadata("design:returntype", Promise)
], ManagementInPort.prototype, "updateConfigVersion", null);
__decorate([
    LogError,
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [UpdateConfigRequest]),
    __metadata("design:returntype", Promise)
], ManagementInPort.prototype, "updateConfig", null);
__decorate([
    LogError,
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [UpdateResolverRequest]),
    __metadata("design:returntype", Promise)
], ManagementInPort.prototype, "updateResolver", null);
__decorate([
    LogError,
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [GetConfigInfoRequest]),
    __metadata("design:returntype", Promise)
], ManagementInPort.prototype, "getConfigInfo", null);
ManagementInPort = __decorate([
    __param(2, lazyInject(MirrorNodeAdapter)),
    __metadata("design:paramtypes", [CommandBus,
        QueryBus,
        MirrorNodeAdapter])
], ManagementInPort);
const Management = new ManagementInPort();
export default Management;
