import { BaseModel } from 'src/common/entities/base.entity';
import { CowModel } from 'src/cow/entities/cow.entity';
import { FarmModel } from 'src/farm/entities/farm.entity';
import { GenomeTraitDetailModel } from './genome-trait-detail.entity';
import {
  Column,
  Entity,
  JoinColumn,
  ManyToOne,
  OneToMany,
  PrimaryGeneratedColumn,
} from 'typeorm';

/**
 * 유전체 분석 의뢰 (tb_genome_request)
 * 1개체 N의뢰 관계
 */
@Entity({ name: 'tb_genome_request' })
export class GenomeRequestModel extends BaseModel {
  @PrimaryGeneratedColumn({
    name: 'pk_request_no',
    type: 'int',
    comment: 'No (PK)',
  })
  pkRequestNo: number;

  @Column({
    name: 'fk_farm_no',
    type: 'int',
    nullable: true,
    comment: '농장번호 FK',
  })
  fkFarmNo: number;

  @Column({
    name: 'fk_cow_no',
    type: 'int',
    nullable: true,
    comment: '개체번호 FK',
  })
  fkCowNo: number;

  @Column({
    name: 'cow_remarks',
    type: 'varchar',
    length: 500,
    nullable: true,
    comment: '개체 비고',
  })
  cowRemarks: string;

  @Column({
    name: 'request_dt',
    type: 'date',
    nullable: true,
    comment: '접수일자',
  })
  requestDt: Date;

  @Column({
    name: 'snp_test',
    type: 'varchar',
    length: 10,
    nullable: true,
    comment: 'SNP 검사',
  })
  snpTest: string;

  @Column({
    name: 'ms_test',
    type: 'varchar',
    length: 10,
    nullable: true,
    comment: 'MS 검사',
  })
  msTest: string;

  @Column({
    name: 'sample_amount',
    type: 'varchar',
    length: 50,
    nullable: true,
    comment: '모근량',
  })
  sampleAmount: string;

  @Column({
    name: 'sample_remarks',
    type: 'varchar',
    length: 500,
    nullable: true,
    comment: '모근 비고',
  })
  sampleRemarks: string;

  // 칩 분석 정보
  @Column({
    name: 'chip_no',
    type: 'varchar',
    length: 50,
    nullable: true,
    comment: '분석 Chip 번호',
  })
  chipNo: string;

  @Column({
    name: 'chip_type',
    type: 'varchar',
    length: 50,
    nullable: true,
    comment: '분석 칩 종류',
  })
  chipType: string;

  @Column({
    name: 'chip_info',
    type: 'varchar',
    length: 200,
    nullable: true,
    comment: '칩정보',
  })
  chipInfo: string;

  @Column({
    name: 'chip_remarks',
    type: 'varchar',
    length: 500,
    nullable: true,
    comment: '칩 비고',
  })
  chipRemarks: string;

  @Column({
    name: 'chip_sire_name',
    type: 'varchar',
    length: 100,
    nullable: true,
    comment: '칩분석 아비명',
  })
  chipSireName: string;

  @Column({
    name: 'chip_dam_name',
    type: 'varchar',
    length: 100,
    nullable: true,
    comment: '칩분석 어미명',
  })
  chipDamName: string;

  @Column({
    name: 'chip_report_dt',
    type: 'date',
    nullable: true,
    comment: '칩분석 보고일자',
  })
  chipReportDt: Date;

  // MS 검사 결과
  @Column({
    name: 'ms_result_status',
    type: 'varchar',
    length: 50,
    nullable: true,
    comment: 'MS 감정결과',
  })
  msResultStatus: string;

  @Column({
    name: 'ms_father_estimate',
    type: 'varchar',
    length: 100,
    nullable: true,
    comment: 'MS 추정부',
  })
  msFatherEstimate: string;

  @Column({
    name: 'ms_report_dt',
    type: 'date',
    nullable: true,
    comment: 'MS 보고일자',
  })
  msReportDt: Date;

  // Relations
  @ManyToOne(() => CowModel, { onDelete: 'CASCADE' })
  @JoinColumn({ name: 'fk_cow_no' })
  cow: CowModel;

  @ManyToOne(() => FarmModel, { onDelete: 'CASCADE' })
  @JoinColumn({ name: 'fk_farm_no' })
  farm: FarmModel;

  @OneToMany(() => GenomeTraitDetailModel, (trait) => trait.genomeRequest)
  traitDetails: GenomeTraitDetailModel[];
}
