import { encodeFunctionData, } from "viem";
import { ContractType, ENVIRONMENT } from "../types/dimo.js";
import { CHAIN_ABI_MAPPING, ENV_MAPPING } from "../constants/mappings.js";
import { MINT_VEHICLE_WITH_DEVICE_DEFINITION } from "../constants/methods.js";
import { executeTransaction } from "../transactions/execute.js";
export function mintVehicleCallData(args, environment = "prod") {
    var _a;
    const contracts = CHAIN_ABI_MAPPING[(_a = ENV_MAPPING.get(environment)) !== null && _a !== void 0 ? _a : ENVIRONMENT.DEV].contracts;
    return encodeFunctionData({
        abi: contracts[ContractType.DIMO_REGISTRY].abi,
        functionName: MINT_VEHICLE_WITH_DEVICE_DEFINITION,
        args: [args.manufacturerNode, args.owner, args.deviceDefinitionID, args.attributeInfo, args.sacdInput],
    });
}
export const mintVehicleTransaction = 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 mintCallData = mintVehicleCallData(args, config.environment);
    const txData = {
        callType: "call",
        to: contracts[ContractType.DIMO_REGISTRY].address,
        value: BigInt("0"),
        data: mintCallData,
    };
    const resp = await executeTransaction(subOrganizationId, walletAddress, txData, passkeyStamper, config);
    return resp;
};
export const mintVehicleWithDeviceDefinition = async (args, client, environment = "prod") => {
    var _a;
    const contracts = CHAIN_ABI_MAPPING[(_a = ENV_MAPPING.get(environment)) !== null && _a !== void 0 ? _a : ENVIRONMENT.DEV].contracts;
    return await client.account.encodeCallData({
        to: contracts[ContractType.DIMO_REGISTRY].address,
        value: BigInt(0),
        data: encodeFunctionData({
            abi: contracts[ContractType.DIMO_REGISTRY].abi,
            functionName: MINT_VEHICLE_WITH_DEVICE_DEFINITION,
            args: [args.manufacturerNode, args.owner, args.deviceDefinitionID, args.attributeInfo, args.sacdInput],
        }),
    });
};
export const mintVehicleWithDeviceDefinitionBatch = async (args, client, environment = "prod") => {
    var _a;
    const contracts = CHAIN_ABI_MAPPING[(_a = ENV_MAPPING.get(environment)) !== null && _a !== void 0 ? _a : ENVIRONMENT.DEV].contracts;
    const callData = args.map((arg) => {
        return {
            to: contracts[ContractType.DIMO_REGISTRY].address,
            value: BigInt(0),
            data: encodeFunctionData({
                abi: contracts[ContractType.DIMO_REGISTRY].abi,
                functionName: MINT_VEHICLE_WITH_DEVICE_DEFINITION,
                args: [arg.manufacturerNode, arg.owner, arg.deviceDefinitionID, arg.attributeInfo, arg.sacdInput],
            }),
        };
    });
    return await client.account.encodeCallData(callData);
};
export const mintVehicleWithDeviceDefinitionFromAccount = async (args, walletClient, publicClient, environment = "prod") => {
    var _a;
    const contracts = CHAIN_ABI_MAPPING[(_a = ENV_MAPPING.get(environment)) !== null && _a !== void 0 ? _a : ENVIRONMENT.DEV].contracts;
    const { request } = await publicClient.simulateContract({
        address: contracts[ContractType.DIMO_REGISTRY].address,
        abi: contracts[ContractType.DIMO_REGISTRY].abi,
        functionName: MINT_VEHICLE_WITH_DEVICE_DEFINITION,
        args: [args.manufacturerNode, args.owner, args.deviceDefinitionID, args.attributeInfo, args.sacdInput],
        account: walletClient.account,
    });
    const txHash = await walletClient.writeContract(request);
    return txHash;
};
//# sourceMappingURL=mintVehicleWithDeviceDefinition.js.map