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

export enum AssetLinkType {
  MENTION = 'mention',
  FORMULA = 'formula',
  TASK = 'task',
}

@Entity('asset_link_comps', { schema: 'public' })
export class AssetLinkEntity {
  @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({ required: true })
  assetId: string;

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

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

  @PrimaryColumn('varchar', {
    name: 'block_prop',
    nullable: false,
  })
  blockProp: string;

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

  @PrimaryColumn('varchar', {
    name: 'link_type',
  })
  @ApiProperty({})
  linkType: AssetLinkType;
}
