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

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

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

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

  @PrimaryColumn('uuid', {
    name: 'comment_id',
    nullable: false,
  })
  @ApiProperty({})
  commentId: string;

  @Column('jsonb', {
    name: 'anchor',
  })
  @ApiProperty({})
  anchor: AssetProps | null;
}
