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

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

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

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

  @Column('integer', {
    nullable: true,
    name: 'user_id',
  })
  userId: number | null;

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