import { DB_SCHEMA } from 'src/utils';
import {
  Column,
  Entity,
  Index,
  JoinColumn,
  ManyToOne,
  PrimaryGeneratedColumn,
} from 'typeorm';
import { UserEntity } from './User.entity';
import { B2bAffiliateAccountsEntity } from './B2bAffiliateAccounts.entity';
import { CompanyBankAccountEntity } from './CompanyBankAccount.entity';
import { PaymentModeMasterEntity } from './PaymentModeMaster.entity';
import { B2bAffiliateAccountBanksEntity } from './B2bAffiliateAccountBanks.entity';

@Index('associate_id', ['associate_id'], {})
@Entity('vcm_sub_agent_bonus_paid', { schema: DB_SCHEMA })
export class VcmSubAgentBonusPaidEntity {
  @PrimaryGeneratedColumn({ type: 'mediumint', name: 'id', unsigned: true })
  id: number;

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

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

  @Column('varchar', { name: 'currency', length: 5, default: 'INR' })
  currency: 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,
    comment: 'WOSAL Account',
  })
  from_bank_account_id: number | null;

  @Column('smallint', {
    name: 'to_bank_account_id',
    nullable: true,
    comment: 'Sub-Agent Account',
    unsigned: true,
  })
  to_bank_account_id: number | null;

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

  @Column('json', {
    name: 'attachment_file',
    nullable: true,
    comment: 'Transaction Screenshot',
  })
  attachment_file: string[] | 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(() => 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;
}
