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

@ViewEntity('actual_project_licenses', { schema: 'public' })
export class ActualProjectLicenseEntity {
  @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('varchar', {
    name: 'license_type_name',
  })
  licenseTypeName: string;

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

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

  @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;
}
