import { DB_SCHEMA } from 'src/utils';
import {
  Column,
  Entity,
  Index,
  JoinColumn,
  OneToOne,
  PrimaryGeneratedColumn,
} from 'typeorm';
import { VcmInstituteCommissionEnquiryEntity } from './VcmInstituteCommissionEnquiry.entity';

@Index('association_type', ['association_type'], {})
@Index('branch_state_id', ['branch_state_id'], {})
@Index('enquiry_id', ['enquiry_id'], {})
@Index('financial_year', ['financial_year'], {})
@Entity('vcm_commission_invoice', { schema: DB_SCHEMA })
export class VcmCommissionInvoiceEntity {
  @PrimaryGeneratedColumn({ type: 'mediumint', name: 'id', unsigned: true })
  id: number;

  @Column('mediumint', { name: 'enquiry_id', unsigned: true })
  enquiry_id: number;

  @Column('tinyint', {
    name: 'association_type',
    comment: '1=Institute, 2= Master Agent, 3=Sub-Agent',
  })
  association_type: number;

  @Column('smallint', { name: 'branch_state_id' })
  branch_state_id: number;

  @Column('varchar', { name: 'financial_year', length: 10 })
  financial_year: string;

  @Column('mediumint', { name: 'serial_no' })
  serial_no: number;

  @Column('varchar', { name: 'invoice_no', length: 50 })
  invoice_no: string;

  @OneToOne(
    () => VcmInstituteCommissionEnquiryEntity,
    (enquiry) => enquiry.invoice,
    {
      onDelete: 'CASCADE',
    },
  )
  @JoinColumn({ name: 'enquiry_id' })
  enquiry: VcmInstituteCommissionEnquiryEntity;
}
