// 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 { singleton } from "tsyringe";
import Injectable from "../../../core/injectable/Injectable";
import { QueryBus } from "../../../core/query/QueryBus";
import { AccountIdNotValid } from "../../../domain/context/account/error/AccountIdNotValid";
import { GetAccountInfoQuery } from "../../usecase/query/account/info/GetAccountInfoQuery";
import EvmAddress from "../../../domain/context/contract/EvmAddress";
import { HEDERA_FORMAT_ID_REGEX } from "../../../domain/context/shared/HederaId";
import { MirrorNodeAdapter } from "../../../port/out/mirror/MirrorNodeAdapter";
import { EVM_ZERO_ADDRESS } from "../../../core/Constants";
import Service from "../Service";
import NetworkService from "../network/NetworkService";
import TransactionService from "../transaction/TransactionService";
let AccountService = class AccountService extends Service {
    networkService;
    transactionService;
    mirrorNodeAdapter;
    queryBus;
    constructor(networkService = Injectable.resolve(NetworkService), transactionService = Injectable.resolve(TransactionService), mirrorNodeAdapter = Injectable.resolve(MirrorNodeAdapter)) {
        super();
        this.networkService = networkService;
        this.transactionService = transactionService;
        this.mirrorNodeAdapter = mirrorNodeAdapter;
    }
    getCurrentAccount() {
        this.queryBus = Injectable.resolve(QueryBus);
        return this.transactionService.getHandler().getAccount();
    }
    async getAccountInfo(id) {
        this.queryBus = Injectable.resolve(QueryBus);
        const account = (await this.queryBus.execute(new GetAccountInfoQuery(id))).account;
        if (!account.id)
            throw new AccountIdNotValid(id.toString());
        return account;
    }
    async getAccountEvmAddress(accountId) {
        const evmAddress = HEDERA_FORMAT_ID_REGEX.test(accountId)
            ? await this.mirrorNodeAdapter.accountToEvmAddress(accountId)
            : new EvmAddress(accountId);
        return evmAddress;
    }
    async getAccountEvmAddressOrNull(accountId) {
        const evmAddress = accountId === "0.0.0" ? new EvmAddress(EVM_ZERO_ADDRESS) : await this.getAccountEvmAddress(accountId);
        return evmAddress;
    }
};
AccountService = __decorate([
    singleton(),
    __metadata("design:paramtypes", [NetworkService,
        TransactionService,
        MirrorNodeAdapter])
], AccountService);
export default AccountService;
