import { BaseModel } from 'src/common/entities/base.entity';
import { FarmModel } from 'src/farm/entities/farm.entity';
import {
  Column,
  Entity,
  JoinColumn,
  ManyToOne,
  PrimaryGeneratedColumn,
} from 'typeorm';

/**
 * 개체 기본 정보 (tb_cow)
 * 암소/수소, 부모 혈통 포함
 */
@Entity({ name: 'tb_cow' })
export class CowModel extends BaseModel {
  @PrimaryGeneratedColumn({
    name: 'pk_cow_no',
    type: 'int',
    comment: '내부 PK (자동증가)',
  })
  pkCowNo: number;

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

  @Column({
    name: 'cow_sex',
    type: 'varchar',
    length: 1,
    nullable: true,
    comment: '성별 (암/수)',
  })
  cowSex: string;

  @Column({
    name: 'cow_birth_dt',
    type: 'date',
    nullable: true,
    comment: '생년월일',
  })
  cowBirthDt: Date;

  @Column({
    name: 'sire_kpn',
    type: 'varchar',
    length: 20,
    nullable: true,
    comment: '부(씨수소) KPN번호',
  })
  sireKpn: string;

  @Column({
    name: 'dam_cow_id',
    type: 'varchar',
    length: 20,
    nullable: true,
    comment: '모(어미소) 개체식별번호 (KOR)',
  })
  damCowId: string;

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

  @Column({
    name: 'cow_status',
    type: 'varchar',
    length: 20,
    nullable: true,
    comment: '개체상태',
  })
  cowStatus: string;

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