import { AssetClass } from '@3rd-eye-labs/cardano-offchain-common';
import { InterestOracleParams } from '../interest-oracle/types';
import { PriceOracleParams } from '../price-oracle/types';
import { Rational } from '../../types/rational';
import { PythFeedParamsSP } from '../../types/system-params';

export type CollateralAssetInfo = {
  collateralAsset: AssetClass;
  oracleParams: PriceOracleParams | undefined;
  interestOracleParams: InterestOracleParams;
  interestOracleNft: AssetClass;
};

export type AssetInfo = {
  iassetTokenNameAscii: string;
  collateralAssets: CollateralAssetInfo[];
};

/** Price oracle config for indigo oracle (used during initialize) */
export type IndigoOracleNftParam = {
  tag: '_indigo_oracle_nft';
  tokenName: string;
  startPrice: Rational;
  params: {
    biasTime: bigint;
    expirationPeriod: bigint;
  };
};

/** Price oracle config for Pyth (used during initialize) */
export type PythOracleParam = {
  tag: '_pyth_oracle_nft';
  pythFeedParams: PythFeedParamsSP;
};

export type PriceOracleParam = IndigoOracleNftParam | PythOracleParam;

export type InitialStablepoolParam = {
  collateralAsset: AssetClass;
  collateralToIassetRatio: Rational;
  mintingFeeRatio: Rational;
  redemptionFeeRatio: Rational;
  mintingEnabled: boolean;
  redemptionEnabled: boolean;
  feeManager: string | undefined;
  minMintOrderAmount: bigint;
  minRedemptionOrderAmount: bigint;
};

/** Collateral asset input for initialize */
export type InitialCollateralAssetParam = {
  collateralAsset: AssetClass;
  extraDecimals: bigint;
  priceOracle: PriceOracleParam;
  interestOracle: {
    tokenName: string;
    initialInterestRate: bigint;
    params: {
      biasTime: bigint;
    };
  };
  redemptionRatio: Rational;
  maintenanceRatio: Rational;
  liquidationRatio: Rational;
  minCollateralAmt: bigint;
  firstCollateralAsset: boolean;
  nextCollateralAsset: AssetClass | undefined;
};

/** IAsset input for initialize */
export type InitialAssetParam = {
  name: string;
  collateralAssets: InitialCollateralAssetParam[];
  stablepools: InitialStablepoolParam[];
  debtMintingFeeRatio: Rational;
  liquidationProcessingFeeRatio: Rational;
  stabilityPoolWithdrawalFeeRatio: Rational;
  redemptionReimbursementRatio: Rational;
  redemptionProcessingFeeRatio: Rational;
  firstAsset: boolean;
  nextAsset?: string | undefined;
};

/** Configurable options for protocol initialization */
export type InitializeOptions = {
  /** Number of CDP creator UTxOs to create */
  numCdpCreators: bigint;
  /** Number of collector UTxOs to create */
  numCollectors: bigint;
  /** Number of interest collector UTxOs to create */
  numInterestCollectors: bigint;
  /** Number of treasury UTxo deployments */
  numTreasuryUtxos: bigint;
  /** INDY amount to send to the treasury */
  treasuryIndyAmount: bigint;
  /** Total INDY token supply to mint */
  totalIndySupply: bigint;

  /** Stability pool: fee in lovelace to create an SP account */
  accountCreateFeeLovelaces: bigint;
  /** Stability pool: cooldown between account processing (ms) */
  accountProcessingCooldownMs: bigint;

  /** Interest collection: cooldown between interest settlement (slot) */
  interestSettlementCooldown: bigint;

  /** CDP redeem: extra fee in lovelace for partial redemption */
  partialRedemptionExtraFeeLovelace: number;
  /** Default Protocol bias time (ms). Used for CDP, CDP Redeem, Stability Pool, Interest Collection, Interest Oracle, Price Oracle, and Stableswap. */
  biasTime: bigint;
  gBiasTime?: bigint;
  accountProcessingBiasTime?: bigint;

  /** Lovelace per interest collector deployment UTxO */
  interestCollectorUtxoLovelaces: bigint;
};
