import { BlockchainType, Coin } from "./common";

export declare enum TransactionStatus {
    SUCCESS = "SUCCESS",
    FAIL = "FAIL",
}

export declare enum TransactionTypeEnum {
    GENERIC = "GENERIC",
    MINING = "MINING",
    MIXING = "MIXING",
    CONTRACT_CALL = "CONTRACT_CALL",
    DEX_TRADE = "DEX_TRADE",
    LIGHTNING = "LIGHTNING",
    CROSS_CHAIN = "CROSS_CHAIN",
    SYSTEM = "SYSTEM",
    DEPOSIT = "DEPOSIT",
}

export interface Transaction {
    hash: string;
    blockchain: string;
    timestamp: number;
    cases: Array<{ id: number; name: string }>;
    numberOfConfirmations: number;
    block: number;
    fees: {
        amount: number;
        unit: string;
        amountUsd: number;
        energy?: {
            provided?: number;
            unit?: string;
            consumed?: number;
            consumedPercent?: number;
            price?: EnergyPrice;
        };
    };
    tags: TransactionTypeEnum[];
    signers: Signer[];
    status: {
        scorechain: TransactionStatus;
        blockchainStatus: string;
    };
    operations: Operation[];
    blockchainSpecific: {
        lightningNetwork: LightningAPIResponse;
        crossChainSwaps: Array<CrossChainSwap>;
    };
}

export interface LightningAPIResponse {
    capacity: {
        amount: number;
        amountUsd: number;
        unit: string;
    };
    channelOperation: string;
    node1: {
        alias?: string;
        hash: string;
        ip?: string;
        location?: {
            city: string;
            country: string;
            isoCode: string;
        };
    };
    node2: {
        alias?: string;
        hash: string;
        ip?: string;
        location?: {
            city: string;
            country: string;
            isoCode: string;
        };
    };
}

export interface CrossChainSwapActorTransaction {
    hash: string;
    isCurrent: boolean;
}

export interface CrossChainSwapActor {
    blockchain: BlockchainType;
    address: string;
    transaction: CrossChainSwapActorTransaction;
    coin: Coin;
    amount: number;
    amountUsd: number;
    entity: MinimalEntity;
}

export interface CrossChainSwap {
    protocol: string;
    origin: CrossChainSwapActor;
    destination: CrossChainSwapActor;
    duration: number;
}

export interface Operation {
    type: string;
    sources: OperationMember[];
    destinations: OperationMember[];
    coin: Coin;
    amount: number;
    amountUsd: number;
    status: string;
}

export interface OperationMember {
    address: string;
    isContract: boolean;
    amount: number;
    amountUsd?: number;
    entity?: {
        id: number;
        name: string;
        type: string;
    };
    linkedTransaction?: { hash: string };
}

export interface Signer {
    addresses: string[];
    entity?: Pick<Entity, "id" | "name" | "type">;
}

export interface EnergyPrice {
    amount: number;
    unit: string;
}

export type MinimalEntity = Pick<Entity, "id" | "name" | "type">;

export interface Entity {
    id?: number;
    name: string;
    type: string;
    typeId?: number;
    score?: number;
    countries?: string[];
    comment?: string;
    description?: string;
}
