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

@Entity('assets', { schema: 'public' })
export class AssetEntity {
  @PrimaryColumn('uuid', {
    name: 'id',
    nullable: false,
  })
  id: string;

  @Column('uuid', {
    name: 'workspace_id',
  })
  workspaceId: string;

  @Column('uuid', {
    name: 'parent_ids',
    array: true,
  })
  parentIds: string[];

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

  @Column('varchar', {
    name: 'name',
  })
  name: string;

  @Column('varchar', {
    name: 'title',
  })
  title: string;

  @Column('varchar', {
    name: 'icon',
  })
  icon: string;

  @Column('float4', {
    name: 'index',
  })
  index: number | null;

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

  @Column('boolean', {
    name: 'is_abstract',
  })
  isAbstract: boolean;

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

  @Column('timestamp with time zone', {
    name: 'deleted_at',
  })
  deletedAt?: Date;

  @Column('integer', {
    name: 'creator_user_id',
  })
  creatorUserId: number;

  @Column('integer', {
    name: 'scope_id',
  })
  scopeId: number;
}
