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

/**
 * 농장 정보 (tb_farm)
 * 1사용자 N농장 관계
 */
@Entity({ name: 'tb_farm' })
export class FarmModel extends BaseModel {
  @PrimaryGeneratedColumn({
    name: 'pk_farm_no',
    type: 'int',
    comment: '내부 PK (자동증가)',
  })
  pkFarmNo: number;

  @Column({
    name: 'trace_farm_no',
    type: 'varchar',
    length: 50,
    nullable: true,
    comment: '축평원 농장번호 (나중에 입력)',
  })
  traceFarmNo: string;

  @Column({
    name: 'fk_user_no',
    type: 'int',
    nullable: true,
    comment: '사용자정보 FK',
  })
  fkUserNo: number;

  @Column({
    name: 'farmer_name',
    type: 'varchar',
    length: 100,
    nullable: true,
    comment: '농장주명 (농가명을 농장주로 사용)',
  })
  farmerName: string;

  @Column({
    name: 'region_si',
    type: 'varchar',
    length: 50,
    nullable: true,
    comment: '시군',
  })
  regionSi: string;

  @Column({
    name: 'region_gu',
    type: 'varchar',
    length: 50,
    nullable: true,
    comment: '시/군/구 (지역)',
  })
  regionGu: string;

  @Column({
    name: 'road_address',
    type: 'varchar',
    length: 500,
    nullable: true,
    comment: '도로명 주소',
  })
  roadAddress: string;

  // Relations
  @ManyToOne(() => UserModel, { onDelete: 'CASCADE' })
  @JoinColumn({ name: 'fk_user_no' })
  user: UserModel;
}
