"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 tsyringe_1 = require("tsyringe");
const Injectable_1 = __importDefault(require("../../../core/injectable/Injectable"));
const NetworkService_1 = __importDefault(require("../network/NetworkService"));
const Service_1 = __importDefault(require("../Service"));
const TransactionService_1 = __importDefault(require("../transaction/TransactionService"));
const EvmAddress_1 = __importDefault(require("../../../domain/context/contract/EvmAddress"));
const HederaId_1 = require("../../../domain/context/shared/HederaId");
const MirrorNodeAdapter_1 = require("../../../port/out/mirror/MirrorNodeAdapter");
let ContractService = class ContractService extends Service_1.default {
    networkService;
    transactionService;
    mirrorNodeAdapter;
    queryBus;
    constructor(networkService = Injectable_1.default.resolve(NetworkService_1.default), transactionService = Injectable_1.default.resolve(TransactionService_1.default), mirrorNodeAdapter = Injectable_1.default.resolve(MirrorNodeAdapter_1.MirrorNodeAdapter)) {
        super();
        this.networkService = networkService;
        this.transactionService = transactionService;
        this.mirrorNodeAdapter = mirrorNodeAdapter;
    }
    async getContractEvmAddress(contractId) {
        return new EvmAddress_1.default(HederaId_1.HEDERA_FORMAT_ID_REGEX.test(contractId)
            ? (await this.mirrorNodeAdapter.getContractInfo(contractId)).evmAddress
            : contractId.toString());
    }
    async getEvmAddressesFromHederaIds(addresses) {
        if (!addresses)
            return [];
        return Promise.all(addresses.map((address) => this.getContractEvmAddress(address.toString())));
    }
};
ContractService = __decorate([
    (0, tsyringe_1.singleton)(),
    __metadata("design:paramtypes", [NetworkService_1.default,
        TransactionService_1.default,
        MirrorNodeAdapter_1.MirrorNodeAdapter])
], ContractService);
exports.default = ContractService;
