"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 });
const QueryBus_1 = require("../../../core/query/QueryBus");
const Injectable_1 = __importDefault(require("../../../core/injectable/Injectable"));
const GetRegulationDetailsRequest_1 = __importDefault(require("../request/factory/GetRegulationDetailsRequest"));
const LogErrorDecorator_1 = require("../../../core/decorator/LogErrorDecorator");
const ValidatedArgs_1 = __importDefault(require("../../../core/validation/ValidatedArgs"));
const GetRegulationDetailsQuery_1 = require("../../../app/usecase/query/factory/get/GetRegulationDetailsQuery");
const ContractId_1 = __importDefault(require("../../../domain/context/contract/ContractId"));
const NetworkService_1 = __importDefault(require("../../../app/service/network/NetworkService"));
class FactoryInPort {
    queryBus;
    networkService;
    constructor(queryBus = Injectable_1.default.resolve(QueryBus_1.QueryBus), networkService = Injectable_1.default.resolve(NetworkService_1.default)) {
        this.queryBus = queryBus;
        this.networkService = networkService;
    }
    async getRegulationDetails(request) {
        ValidatedArgs_1.default.handleValidation("GetRegulationDetailsRequest", request);
        const securityFactory = this.networkService.configuration.factoryAddress;
        const res = await this.queryBus.execute(new GetRegulationDetailsQuery_1.GetRegulationDetailsQuery(request.regulationType, request.regulationSubType, securityFactory ? new ContractId_1.default(securityFactory) : undefined));
        const regulation = res.regulation;
        return {
            ...regulation,
        };
    }
}
__decorate([
    LogErrorDecorator_1.LogError,
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [GetRegulationDetailsRequest_1.default]),
    __metadata("design:returntype", Promise)
], FactoryInPort.prototype, "getRegulationDetails", null);
const Factory = new FactoryInPort();
exports.default = Factory;
