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

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

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

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

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

  @Column({ type: 'enum', enum: PairType })
    type!: PairType;

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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