import { BaseModel } from 'src/common/entities/base.entity';
import { GenomeRequestModel } from 'src/genome/entities/genome-request.entity';
import {
  Column,
  Entity,
  Index,
  JoinColumn,
  ManyToOne,
  PrimaryGeneratedColumn,
} from 'typeorm';

/**
 * 유전자 상세 정보 (tb_gene_detail)
 * 1개체당 N개 SNP 마커 결과 저장
 * 예: KOR002108023350, 1:110900379, 1, 110900379, [A/T], A, A, 설명
 */
@Entity({ name: 'tb_gene_detail' })
@Index('idx_gene_detail_cow_id', ['cowId'])
@Index('idx_gene_detail_snp_name', ['snpName'])
@Index('idx_gene_detail_cow_snp', ['cowId', 'snpName'])
export class GeneDetailModel extends BaseModel {
  @PrimaryGeneratedColumn({
    name: 'pk_gene_detail_no',
    type: 'int',
    comment: '유전자상세번호 PK',
  })
  pkGeneDetailNo: number;

  @Column({
    name: 'fk_request_no',
    type: 'int',
    nullable: true,
    comment: '의뢰번호 FK',
  })
  fkRequestNo: number;

  @Column({
    name: 'cow_id',
    type: 'varchar',
    length: 20,
    nullable: true,
    comment: '개체식별번호 (KOR)',
  })
  cowId: string;

  @Column({
    name: 'snp_name',
    type: 'varchar',
    length: 100,
    nullable: true,
    comment: 'SNP 이름 (예: 1:110900379)',
  })
  snpName: string;

  @Column({
    name: 'chromosome',
    type: 'varchar',
    length: 10,
    nullable: true,
    comment: '염색체 위치 (Chr)',
  })
  chromosome: string;

  @Column({
    name: 'position',
    type: 'varchar',
    length: 20,
    nullable: true,
    comment: '위치 (Position)',
  })
  position: string;

  @Column({
    name: 'snp_type',
    type: 'varchar',
    length: 20,
    nullable: true,
    comment: 'SNP 구분 (예: [A/T])',
  })
  snpType: string;

  @Column({
    name: 'allele1',
    type: 'varchar',
    length: 10,
    nullable: true,
    comment: '첫번째 대립유전자 (Allele1...Top)',
  })
  allele1: string;

  @Column({
    name: 'allele2',
    type: 'varchar',
    length: 10,
    nullable: true,
    comment: '두번째 대립유전자 (Allele2...Top)',
  })
  allele2: string;

  @Column({
    name: 'remarks',
    type: 'varchar',
    length: 500,
    nullable: true,
    comment: '비고 (설명)',
  })
  remarks: string;

  // Relations
  @ManyToOne(() => GenomeRequestModel, { onDelete: 'CASCADE' })
  @JoinColumn({ name: 'fk_request_no' })
  genomeRequest: GenomeRequestModel;
}
