import { DB_SCHEMA } from 'src/utils';
import {
  Column,
  Entity,
  Index,
  JoinColumn,
  ManyToOne,
  OneToMany,
  PrimaryGeneratedColumn,
} from 'typeorm';
import { UserEntity } from './User.entity';
import { CountryEntity } from './Country.entity';
import { VcmCommissionContractSetsEntity } from './VcmCommissionContractSets.entity';
import { ProductMasterEntity } from './ProductMaster.entity';
import { VcmCommissionContractsHistoryEntity } from './VcmCommissionContractsHistory.entity';
import { VcmCommissionContractApplicableOnEntity } from './VcmCommissionContractApplicableOn.entity';
import { CollegeEntity } from './College.entity';
@Index('associate_id', ['associate_id'], {})
@Index('association_type', ['association_type'], {})
@Index('product_id', ['product_id'], {})
@Index('student_condition', ['student_condition'], {})
@Index('visa_service_country_id', ['visa_service_country_id'], {})
@Entity('vcm_commission_contracts', { schema: DB_SCHEMA })
export class VcmCommissionContractsEntity {
  @PrimaryGeneratedColumn({ type: 'mediumint', name: 'id', unsigned: true })
  id: number;

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

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

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

  @Column('mediumint', {
    name: 'associate_id',
    comment: 'Master Agent / Sub Agent',
    unsigned: true,
    nullable: true,
  })
  associate_id?: number;

  @Column('mediumint', {
    name: 'institute_id',
    comment: 'Institute id',
    unsigned: true,
  })
  institute_id: number;

  @Column('json', { name: 'client_from_countries' })
  client_from_countries: object;

  @Column('tinyint', {
    name: 'student_condition',
    comment: 'STUDENT_CONDITION_LIST',
  })
  student_condition: number;

  @Column('json', {
    name: 'attachment_file',
    nullable: true,
    comment: 'General Contract',
  })
  attachment_file: object | null;

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

  @Column('tinyint', { name: 'campus_condition', comment: '1=All, 2=Specific' })
  campus_condition: number;

  @Column('tinyint', {
    name: 'study_level_condition',
    comment: '1=All, 2=Specific',
  })
  study_level_condition: number;

  @Column('tinyint', { name: 'course_condition', comment: '1=All, 2=Specific' })
  course_condition: number;

  @Column('mediumtext', { name: 'notes' })
  notes: string;

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

  @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,
    (visa_country) => visa_country.visa_commission_contract,
  )
  @JoinColumn({ name: 'visa_service_country_id' })
  visa_country: CountryEntity;

  @OneToMany(
    () => VcmCommissionContractApplicableOnEntity,
    (vcmCommissionContractApplicableOn) =>
      vcmCommissionContractApplicableOn.commission_contract,
  )
  vcm_commission_contract_applicable_sets: VcmCommissionContractApplicableOnEntity[];

  @ManyToOne(
    () => ProductMasterEntity,
    (productMaster) => productMaster.vcm_commission_contracts,
    { onDelete: 'NO ACTION', onUpdate: 'NO ACTION' },
  )
  @JoinColumn([{ name: 'product_id', referencedColumnName: 'id' }])
  product: ProductMasterEntity;

  @OneToMany(
    () => VcmCommissionContractsHistoryEntity,
    (vcmCommissionContractsHistory) => vcmCommissionContractsHistory.contract,
  )
  vcmCommissionContractsHistories: VcmCommissionContractsHistoryEntity[];

  @ManyToOne(() => CollegeEntity, (college) => college.collegeId, {
    nullable: true,
  })
  @JoinColumn({ name: 'institute_id' })
  institute: CollegeEntity;
}
