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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

  @Column('numeric', { nullable: true, transformer: bigintTransformer })
    settleTime!: bigint | null;

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

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

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

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

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

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

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

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