import { DB_SCHEMA } from 'src/utils';
import { Column, Entity, Index, PrimaryGeneratedColumn } from 'typeorm';

@Index('case_uid', ['case_uid'], { unique: true })
@Index(
  'lead_id',
  ['lead_id', 'student_id', 'student_package_id', 'ol_converted_id'],
  {},
)
@Entity('vms_visa_cases', { schema: DB_SCHEMA })
export class VmsVisaCasesEntity {
  @PrimaryGeneratedColumn({ type: 'int', name: 'id' })
  id: number;

  @Column('varchar', {
    name: 'case_uid',
    nullable: true,
    unique: true,
    length: 15,
  })
  case_uid: string | null;

  @Column('tinyint', {
    name: 'client_type',
    comment: '1=Primary,2=Co-Applicant',
  })
  client_type: number;

  @Column('tinyint', {
    name: 'case_origin',
    comment: '1=ERP, 2=B2B',
    default: () => "'1'",
  })
  case_origin: number;

  @Column('tinyint', {
    name: 'secondary_applicant_type',
    nullable: true,
    comment: '1=Co-Applicant,2=Collective Applicant',
  })
  secondary_applicant_type: number | null;

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

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

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

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

  @Column('int', {
    name: 'case_applicant_type',
    nullable: true,
    comment: 'Co-Applicant Parent Case Id',
  })
  case_applicant_type: number | null;

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

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

  @Column('smallint', {
    name: 'pipeline_stage',
    nullable: true,
    comment: 'vms_visa_pipeline_stages->id',
  })
  pipeline_stage: number | null;

  @Column('tinyint', {
    name: 'case_category',
    nullable: true,
    comment: 'Original/Iteration',
  })
  case_category: number | null;

  @Column('tinyint', {
    name: 'ol_conversion_status',
    comment: '1=Not Converted,2=Converted ',
    default: () => "'1'",
  })
  ol_conversion_status: number;

  @Column('timestamp', { name: 'first_ol_applied_date', nullable: true })
  first_ol_applied_date: Date | null;

  @Column('date', { name: 'last_ol_received_date', nullable: true })
  last_ol_received_date: string | null;

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

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

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

  @Column('timestamp', { name: 'file_lodged_on', nullable: true })
  file_lodged_on: Date | null;

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

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

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

  @Column('timestamp', { name: 'visa_result_on', nullable: true })
  visa_result_on: Date | null;

  @Column('text', { name: 'last_case_remark', nullable: true })
  last_case_remark: string | null;

  @Column('timestamp', { name: 'last_remark_on', nullable: true })
  last_remark_on: Date | null;

  @Column('tinyint', {
    name: 'iteration_request_status',
    nullable: true,
    comment: '1=In-progress,2=Success,3=Failed',
  })
  iteration_request_status: number | null;

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

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

  @Column('tinyint', {
    name: 'case_state',
    nullable: true,
    comment: 'VISA_CASE_STATE_LIST',
    default: () => "'1'",
  })
  case_state: number | null;

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

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

  @Column('json', { name: 'data_json', nullable: true })
  data_json: object | null;

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

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

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

  @Column('timestamp', { name: 'created', default: () => 'CURRENT_TIMESTAMP' })
  created: Date;

  @Column('timestamp', { name: 'modified', default: () => 'CURRENT_TIMESTAMP' })
  modified: Date;
}
