import { Column, Entity, PrimaryColumn } from 'typeorm';
import { ApiProperty } from '@nestjs/swagger';
import {
  encodeBigNumberKey,
  decodeBigNumberKey,
} from '../utils/big-number-key';

@Entity('asset_references', { schema: 'public' })
export class AssetRefEntity {
  @PrimaryColumn({
    name: 'project_id',
    nullable: false,
    transformer: {
      from: (x) => encodeBigNumberKey(x),
      to: (x) => decodeBigNumberKey(x),
    },
  })
  @ApiProperty({})
  projectId: string;

  @PrimaryColumn('uuid', {
    name: 'asset_id',
  })
  @ApiProperty({})
  assetId: string;

  @PrimaryColumn('uuid', {
    name: 'target_asset_id',
  })
  @ApiProperty({})
  targetAssetId: string;

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

  @PrimaryColumn('bigint', {
    name: 'target_block_key',
  })
  targetBlockKey: string;

  @Column('timestamp with time zone', {
    name: 'created_at',
    nullable: false,
    default: () => 'CURRENT_TIMESTAMP',
  })
  createdAt: Date;
}
