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

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

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

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

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

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

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

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

  @Column('boolean')
    inLiquidation!: boolean;

  @Column('varchar', { nullable: true })
    liquidationAuction!: string | null;

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

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

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

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

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

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

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