/**
 * Cacti Bridge Client
 */
import axios, { AxiosInstance } from 'axios';

export interface CactiTransferParams {
    sourceLedger: 'BESU' | 'FABRIC' | 'ETHEREUM' | 'CORDA';
    destLedger: 'BESU' | 'FABRIC' | 'ETHEREUM' | 'CORDA';
    assetId: string;
    amount: number;
    sender: string;
    recipient: string;
}

export class CactiClient {
    private api: AxiosInstance;

    constructor(apiUrl: string = 'http://192.168.11.177:4000/api/v1') {
        this.api = axios.create({
            baseURL: apiUrl,
            headers: { 'Content-Type': 'application/json' }
        });
    }

    async transferAsset(params: CactiTransferParams): Promise<any> {
        const response = await this.api.post('/plugins/transfer-asset', {
            sourceConnectorId: `${params.sourceLedger.toLowerCase()}-connector`,
            destConnectorId: `${params.destLedger.toLowerCase()}-connector`,
            payload: params
        });
        return response.data;
    }

    async getTransactionStatus(txId: string): Promise<any> {
        const response = await this.api.get(`/transactions/${txId}`);
        return response.data;
    }
}
