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

@Entity('invitations', { schema: 'public' })
export class InvitationEntity {
  @PrimaryGeneratedColumn({ type: 'integer', name: 'id' })
  @ApiProperty({ required: true })
  id: number;

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

  @Column('integer', {
    name: 'inviter_user_id',
    nullable: false
  })
  @ApiProperty({})
  inviterId: number;
  
  @Column('varchar', {
    name: 'guest_email',
    nullable: false
  })
  @ApiProperty({})
  email: string;

  @Column('varchar', {
    name: 'invitation_code',
    nullable: false
  })
  @ApiProperty({})
  code: string;

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