import { DB_SCHEMA } from 'src/utils';
import {
  Column,
  Entity,
  Index,
  JoinColumn,
  ManyToOne,
  PrimaryGeneratedColumn,
} from 'typeorm';
import { UserEntity } from './User.entity';
import { CountryEntity } from './Country.entity';
import { CollegeEntity } from './College.entity';
import { CourseMasterIntakeYearsEntity } from './CourseMasterIntakeYears.entity';
import { B2bAffiliateAccountsEntity } from './B2bAffiliateAccounts.entity';
import { CompanyBankAccountEntity } from './CompanyBankAccount.entity';
import { PaymentModeMasterEntity } from './PaymentModeMaster.entity';
import { VcmCommissionContractSetsEntity } from './VcmCommissionContractSets.entity';
import { VcmCommissionContractInstancesEntity } from './VcmCommissionContractInstances.entity';
import { B2bAffiliateAccountBanksEntity } from './B2bAffiliateAccountBanks.entity';

@Index('associate_id', ['associate_id'], {})
@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_sub_agent_commission', { schema: DB_SCHEMA })
export class VcmSubAgentCommissionEntity {
  @PrimaryGeneratedColumn({ type: 'mediumint', name: 'id', unsigned: true })
  id: number;

  @Column('smallint', { name: 'associate_id', comment: 'Sub-Agent' })
  associate_id: number;

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

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

  @Column('mediumint', {
    name: 'contract_set_id',
  })
  contract_set_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: 'commission_instance', unsigned: true })
  commission_instance: number;

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

  @Column('decimal', { name: 'total_amount_inr', precision: 15, scale: 2 })
  total_amount_inr: string;

  @Column('json', { name: 'tax_details', nullable: true })
  tax_details: Record<any, any> | null;

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

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

  @Column('varchar', { name: 'deduction_reason', nullable: true, length: 500 })
  deduction_reason: string | null;

  @Column('decimal', { name: 'net_amount_inr', precision: 15, scale: 2 })
  net_amount_inr: string;

  @Column('date', { name: 'payment_date' })
  payment_date: string;

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

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

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

  @Column('varchar', { name: 'transaction_id', nullable: true, length: 250 })
  transaction_id: string | null;

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

  @Column('mediumtext', { name: 'remarks', nullable: true })
  remarks: string | 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;

  @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(() => B2bAffiliateAccountsEntity)
  @JoinColumn({ name: 'associate_id' })
  associate: B2bAffiliateAccountsEntity;

  @ManyToOne(() => CompanyBankAccountEntity)
  @JoinColumn({ name: 'from_bank_account_id' })
  from_bank: CompanyBankAccountEntity;

  @ManyToOne(() => B2bAffiliateAccountBanksEntity)
  @JoinColumn({ name: 'to_bank_account_id' })
  to_bank: B2bAffiliateAccountBanksEntity;

  @ManyToOne(() => PaymentModeMasterEntity)
  @JoinColumn({ name: 'payment_mode_id' })
  mode: PaymentModeMasterEntity;

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

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