import { Column, Entity, PrimaryColumn } from 'typeorm';
import { AssetProps } from '../asset/logic/Props';
import {
  encodeBigNumberKey,
  decodeBigNumberKey,
} from '../utils/big-number-key';

@Entity('asset_block_comps', { schema: 'public' })
export class AssetBlockCompEntity {
  @PrimaryColumn('uuid', {
    name: 'asset_id',
    nullable: false,
  })
  assetId: string;

  @PrimaryColumn('bigint', {
    name: 'project_id',
    nullable: false,
    transformer: {
      from: (x) => encodeBigNumberKey(x),
      to: (x) => decodeBigNumberKey(x),
    },
  })
  projectId: string;

  @PrimaryColumn('bigint', {
    name: 'block_key',
    nullable: false,
  })
  blockKey: string;

  @Column('jsonb', {
    name: 'computed_props',
  })
  computedProps: AssetProps;

  @Column('float', {
    name: 'filled_rate',
  })
  filledRate: number | null;

  @Column('timestamp with time zone', {
    name: 'dirty_at',
    nullable: false,
  })
  dirtyAt: Date;

  @Column('timestamp with time zone', {
    name: 'computed_at',
    nullable: true,
  })
  computedAt: Date | null;

  @Column('timestamp with time zone', {
    name: 'staged_at',
    nullable: true,
  })
  stagedAt: Date | null;
}
