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

import { Entity, PrimaryColumn, Column, Index } from 'typeorm';
import { bigintTransformer } from '@cerc-io/util';

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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