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

@Entity('project_licenses', { schema: 'public' })
export class ProjectLicenseEntity {
  @PrimaryColumn('integer', {
    name: 'id',
  })
  id: number;

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

  @Column('integer', {
    name: 'license_type_id',
  })
  licenseTypeId: number;

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

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

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

  @Column('jsonb', {
    name: 'features',
  })
  features: Record<string, any> | null;

  @Column('boolean', {
    name: 'is_trial',
  })
  isTrial: boolean;
}
