import { SuiClient } from '@mysten/sui/client'
import { Transaction, TransactionResult } from '@mysten/sui/transactions'

import { ModuleManager } from '../../module-manager'
import { ObjectOptions } from '../../types'

const MODULE_NAME = 'simple_msglib_ptb_builder'

export class SimpleMessageLibPtbBuilder {
    public packageId: string
    public readonly client: SuiClient
    private readonly objects: ObjectOptions

    constructor(
        packageId: string,
        client: SuiClient,
        objects: ObjectOptions,
        private readonly moduleManager: ModuleManager
    ) {
        this.packageId = packageId
        this.client = client
        this.objects = objects
    }

    // === View Functions ===

    /**
     * Creates a transaction to get PTB builder info
     * @param tx - The transaction to add the move call to
     * @returns Transaction result containing PTB builder information
     */
    getPtbBuilderInfoMoveCall(tx: Transaction): TransactionResult {
        return tx.moveCall({
            target: this.#target('get_ptb_builder_info'),
            arguments: [
                tx.object(this.objects.simpleMessageLibPtbBuilder),
                tx.object(this.objects.endpointV2),
                tx.object(this.objects.simpleMessageLib),
            ],
        })
    }

    /**
     * Generate the full target path for move calls
     * @param name - The function name to call
     * @param module_name - The module name (defaults to MODULE_NAME)
     * @returns The full module path for the move call
     * @private
     */
    #target(name: string, module_name = MODULE_NAME): string {
        return `${this.packageId}::${module_name}::${name}`
    }
}
