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

export enum ActionType {
  TASK_CHANGE = 'task_change',
}

@Entity('project_actions', { schema: 'public' })
export class ProjectActionEntity {
  @PrimaryColumn('uuid', {
    name: 'id',
    nullable: false,
  })
  @ApiProperty({ required: true })
  id: string;

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

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

  @Column('integer', {
    name: 'initiator_user_id',
  })
  @ApiProperty({})
  userId: number;

  @Column('varchar', {
    name: 'action_type',
  })
  @ApiProperty({})
  actionType: ActionType;

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

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

  @Column('timestamp with time zone', {
    name: 'notified_at',
  })
  @ApiProperty({})
  notifiedAt?: Date;
}
