//
// Copyright 2021 Vulcanize, Inc.
//

import { Entity, PrimaryColumn, Column, Index } from 'typeorm';
import { decimalTransformer, bigintTransformer, bigintArrayTransformer } from '@cerc-io/util';
import { Decimal } from 'decimal.js';

@Entity()
@Index(['blockNumber'])
export class Pool {
  @PrimaryColumn('varchar')
    id!: string;

  @PrimaryColumn('varchar', { length: 66 })
    blockHash!: string;

  @Column('integer')
    blockNumber!: number;

  @Column('numeric', { transformer: bigintTransformer })
    createdAtBlockNumber!: bigint;

  @Column('numeric', { transformer: bigintTransformer })
    createdAtTimestamp!: bigint;

  @Column('varchar')
    collateralToken!: string;

  @Column('varchar')
    quoteToken!: string;

  @Column('numeric', { transformer: decimalTransformer })
    poolSize!: Decimal;

  @Column('numeric', { transformer: decimalTransformer })
    t0debt!: Decimal;

  @Column('numeric', { transformer: decimalTransformer })
    inflator!: Decimal;

  @Column('numeric', { transformer: decimalTransformer })
    borrowRate!: Decimal;

  @Column('numeric', { transformer: decimalTransformer })
    lendRate!: Decimal;

  @Column('numeric', { transformer: decimalTransformer })
    borrowFeeRate!: Decimal;

  @Column('numeric', { transformer: decimalTransformer })
    depositFeeRate!: Decimal;

  @Column('numeric', { transformer: decimalTransformer })
    pledgedCollateral!: Decimal;

  @Column('numeric', { transformer: decimalTransformer })
    totalInterestEarned!: Decimal;

  @Column('numeric', { transformer: bigintTransformer })
    txCount!: bigint;

  @Column('varchar')
    poolType!: string;

  @Column('numeric', { transformer: bigintTransformer })
    loansCount!: bigint;

  @Column('varchar')
    maxBorrower!: string;

  @Column('numeric', { transformer: decimalTransformer })
    quoteTokenFlashloaned!: Decimal;

  @Column('numeric', { transformer: decimalTransformer })
    collateralFlashloaned!: Decimal;

  @Column('numeric', { transformer: decimalTransformer })
    hpb!: Decimal;

  @Column('integer')
    hpbIndex!: number;

  @Column('numeric', { transformer: decimalTransformer })
    htp!: Decimal;

  @Column('integer')
    htpIndex!: number;

  @Column('numeric', { transformer: decimalTransformer })
    lup!: Decimal;

  @Column('integer')
    lupIndex!: number;

  @Column('numeric', { transformer: decimalTransformer })
    reserves!: Decimal;

  @Column('numeric', { transformer: decimalTransformer })
    claimableReserves!: Decimal;

  @Column('numeric', { transformer: decimalTransformer })
    claimableReservesRemaining!: Decimal;

  @Column('numeric', { transformer: bigintTransformer })
    burnEpoch!: bigint;

  @Column('numeric', { transformer: decimalTransformer })
    totalAjnaBurned!: Decimal;

  @Column('varchar', { array: true })
    reserveAuctions!: string[];

  @Column('numeric', { transformer: decimalTransformer })
    minDebtAmount!: Decimal;

  @Column('numeric', { transformer: decimalTransformer })
    actualUtilization!: Decimal;

  @Column('numeric', { transformer: decimalTransformer })
    targetUtilization!: Decimal;

  @Column('numeric', { transformer: decimalTransformer })
    totalBondEscrowed!: Decimal;

  @Column('varchar', { array: true })
    liquidationAuctions!: string[];

  @Column('numeric', { transformer: decimalTransformer })
    quoteTokenBalance!: Decimal;

  @Column('numeric', { transformer: decimalTransformer })
    collateralBalance!: Decimal;

  @Column('varchar')
    subsetHash!: string;

  @Column('numeric', { array: true, transformer: bigintArrayTransformer })
    tokenIdsPledged!: bigint[];

  @Column('numeric', { array: true, transformer: bigintArrayTransformer })
    bucketTokenIds!: bigint[];

  @Column('numeric', { array: true, transformer: bigintArrayTransformer })
    tokenIdsAllowed!: bigint[];

  @Column('boolean', { default: false })
    isPruned!: boolean;

  @Column('boolean', { default: false })
    isRemoved!: boolean;
}
