import {
  Column,
  Entity,
  Index,
  OneToMany,
  PrimaryGeneratedColumn,
} from 'typeorm';
import { DB_SCHEMA } from 'src/utils';
import { VcmCommissionContractsEntity } from './VcmCommissionContracts.entity';

@Index('name', ['name'], { unique: true })
@Entity('product_master', { schema: DB_SCHEMA })
export class ProductMasterEntity {
  @PrimaryGeneratedColumn({ type: 'tinyint', name: 'id' })
  id: number;

  @Column('varchar', { name: 'name', unique: true, length: 150 })
  name: string;

  @Column('tinyint', { name: 'division_id', comment: '1=Visa, 2=Academy' })
  division_id: number;

  @Column('tinyint', {
    name: 'is_visa_applicable',
    nullable: true,
    comment: '1=Applicable for Visa',
  })
  is_visa_applicable: number | null;

  @Column('tinyint', { name: 'active', nullable: true, comment: '1=Active' })
  active: number | null;

  @Column('smallint', { name: 'by_user', nullable: true })
  by_user: number | null;

  @Column('timestamp', { name: 'created', default: () => 'CURRENT_TIMESTAMP' })
  created: Date;

  @Column('smallint', { name: 'modified_by_user', nullable: true })
  modified_by_user: number | null;

  @Column('timestamp', { name: 'modified', default: () => 'CURRENT_TIMESTAMP' })
  modified: Date;

  @OneToMany(
    () => VcmCommissionContractsEntity,
    (vcmCommissionContracts) => vcmCommissionContracts.product,
  )
  vcm_commission_contracts: VcmCommissionContractsEntity[];
}
