import { DB_SCHEMA } from 'src/utils';
import {
  Column,
  Entity,
  Index,
  JoinColumn,
  ManyToOne,
  PrimaryGeneratedColumn,
} from 'typeorm';
import { VcmCommissionContractSetsEntity } from './VcmCommissionContractSets.entity';

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

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

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

  @Column('tinyint', {
    name: 'commission_type',
    comment: '1=Fixed, 2=Percentage',
  })
  commission_type: number;

  @Column('decimal', {
    name: 'commission_amount',
    nullable: true,
    precision: 11,
    scale: 2,
  })
  commission_amount: 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(
    () => VcmCommissionContractSetsEntity,
    (vcmCommissionContractSets) =>
      vcmCommissionContractSets.vcm_commission_contract_instances,
    { onDelete: 'CASCADE', onUpdate: 'CASCADE' },
  )
  @JoinColumn([
    { name: 'commission_contract_set_id', referencedColumnName: 'id' },
  ])
  commission_contract_set: VcmCommissionContractSetsEntity;
}
