import { DB_SCHEMA } from 'src/utils';
import {
  Column,
  Entity,
  Index,
  JoinColumn,
  ManyToOne,
  OneToOne,
  PrimaryGeneratedColumn,
} from 'typeorm';
import { UserEntity } from './User.entity';
import { CountryEntity } from './Country.entity';
import { CollegeEntity } from './College.entity';
import { CourseMasterIntakeYearsEntity } from './CourseMasterIntakeYears.entity';
import { CenterLocationEntity } from './CenterLocation.entity';
import { CompanyBankAccountEntity } from './CompanyBankAccount.entity';
import { VcmCommissionInvoiceEntity } from './VcmCommissionInvoice.entity';
import { VcmCommissionContractSetsEntity } from './VcmCommissionContractSets.entity';
import { VcmCommissionContractInstancesEntity } from './VcmCommissionContractInstances.entity';

@Index('client_from_country_id', ['client_from_country_id'], {})
@Index('commission_instance', ['commission_instance'], {})
@Index('institute_id', ['institute_id'], {})
@Index('intake_id', ['intake_id'], {})
@Index('visa_service_country_id', ['visa_service_country_id'], {})
@Entity('vcm_institute_commission_enquiry', {
  schema: DB_SCHEMA,
})
export class VcmInstituteCommissionEnquiryEntity {
  @PrimaryGeneratedColumn({ type: 'mediumint', name: 'id', unsigned: true })
  id: number;

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

  @Column('mediumint', {
    name: 'institute_id',
    comment: 'University / College id',
  })
  institute_id: number;

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

  @Column('int', { name: 'intake_id' })
  intake_id: number;

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

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

  @Column('tinyint', { name: 'commission_instance', unsigned: true })
  commission_instance: number;

  @Column('tinyint', { name: 'invoice_branch_id' })
  invoice_branch_id: number;

  @Column('tinyint', { name: 'invoice_bank_account_id' })
  invoice_bank_account_id: number;

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

  @Column('tinyint', {
    name: 'accept_status',
    nullable: true,
    comment: '1=Fully Accepted, 2=Partial Accepted, 3=Fully Rejected',
  })
  accept_status?: string | number | null;

  @Column('decimal', {
    name: 'net_amount',
    nullable: true,
    precision: 15,
    scale: 2,
  })
  net_amount: string | null;

  @Column('varchar', { name: 'currency', length: 5 })
  currency: string;

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

  @ManyToOne(() => UserEntity, { nullable: true })
  @JoinColumn({ name: 'by_user' })
  user: UserEntity;

  @ManyToOne(() => UserEntity, { nullable: true })
  @JoinColumn({ name: 'modified_by_user' })
  modified_by: UserEntity;

  @ManyToOne(() => CountryEntity)
  @JoinColumn({ name: 'visa_service_country_id' })
  visa_country: CountryEntity;

  @ManyToOne(() => CountryEntity)
  @JoinColumn({ name: 'client_from_country_id' })
  client_country: CountryEntity;

  @ManyToOne(() => CollegeEntity)
  @JoinColumn({ name: 'institute_id' })
  institute: CollegeEntity;

  @ManyToOne(() => CourseMasterIntakeYearsEntity)
  @JoinColumn({ name: 'intake_id' })
  intake: CourseMasterIntakeYearsEntity;

  @ManyToOne(() => CenterLocationEntity)
  @JoinColumn({ name: 'invoice_branch_id' })
  branch: CenterLocationEntity;

  @ManyToOne(() => CompanyBankAccountEntity)
  @JoinColumn({ name: 'invoice_bank_account_id' })
  bank: CompanyBankAccountEntity;

  @OneToOne(() => VcmCommissionInvoiceEntity, (invoice) => invoice.enquiry)
  invoice: VcmCommissionInvoiceEntity;

  @ManyToOne(() => VcmCommissionContractSetsEntity)
  @JoinColumn({ name: 'contract_set_id' })
  contract_set: VcmCommissionContractSetsEntity;

  @ManyToOne(() => VcmCommissionContractInstancesEntity)
  @JoinColumn({ name: 'commission_instance' })
  instance: VcmCommissionContractInstancesEntity;
}
