import { encodeFunctionData } from "viem";
import { ContractType, ENVIRONMENT } from "../types/dimo.js";
import { CHAIN_ABI_MAPPING, ENV_MAPPING } from "../constants/mappings.js";
import { PAIR_AFTERMARKET_DEVICE } from "../constants/methods.js";
import { executeTransaction } from "../transactions/execute.js";
export function pairAftermarketDeviceCallData(args, environment = "prod") {
    var _a;
    const contracts = CHAIN_ABI_MAPPING[(_a = ENV_MAPPING.get(environment)) !== null && _a !== void 0 ? _a : ENVIRONMENT.PROD].contracts;
    return encodeFunctionData({
        abi: contracts[ContractType.DIMO_REGISTRY].abi,
        functionName: PAIR_AFTERMARKET_DEVICE,
        args: [args.aftermarketDeviceNode, args.vehicleNode],
    });
}
export const pairAftermarketDeviceTransaction = async (args, subOrganizationId, walletAddress, passkeyStamper, config) => {
    var _a, _b;
    const env = (_b = ENV_MAPPING.get((_a = config.environment) !== null && _a !== void 0 ? _a : "prod")) !== null && _b !== void 0 ? _b : ENVIRONMENT.PROD;
    const contracts = CHAIN_ABI_MAPPING[env].contracts;
    const txData = {
        callType: "call",
        to: contracts[ContractType.DIMO_REGISTRY].address,
        value: BigInt("0"),
        data: pairAftermarketDeviceCallData(args, config.environment),
    };
    const resp = await executeTransaction(subOrganizationId, walletAddress, txData, passkeyStamper, config);
    return resp;
};
export const pairAftermarketDevice = async (args, client, environment = "prod") => {
    var _a;
    const contracts = CHAIN_ABI_MAPPING[(_a = ENV_MAPPING.get(environment)) !== null && _a !== void 0 ? _a : ENVIRONMENT.PROD].contracts;
    return await client.account.encodeCallData({
        to: contracts[ContractType.DIMO_REGISTRY].address,
        value: BigInt(0),
        data: encodeFunctionData({
            abi: contracts[ContractType.DIMO_REGISTRY].abi,
            functionName: PAIR_AFTERMARKET_DEVICE,
            args: [args.aftermarketDeviceNode, args.vehicleNode],
        }),
    });
};
//# sourceMappingURL=pairAftermarketDevice.js.map