import { Entity, Column, ManyToOne, JoinColumn } from "typeorm";
import { EntityBase } from "./base/Base";
import { ProfileEducation } from "./ProfileEducation";

@Entity("profileEducationHistory")
export class ProfileEducationHistory extends EntityBase {
  @Column({
    nullable: true,
    comment: "ประเทศ",
    length: 1000,
    default: null,
  })
  country: string;

  @Column({
    nullable: true,
    comment: "วุฒิการศึกษา",
    length: 200,
    default: null,
  })
  degree: string;

  @Column({
    nullable: true,
    comment: "ระยะเวลา",
    length: 1000,
    default: null,
  })
  duration: string;

  @Column({
    comment: "ระยะเวลาหลักสูตร",
    nullable: true,
  })
  durationYear: number;

  @Column({
    nullable: true,
    comment: "สาขาวิชา/ทาง",
    length: 200,
    default: null,
  })
  field: string;

  @Column({
    nullable: true,
    type: "datetime",
    comment: "วันที่สำเร็จการศึกษา",
    default: null,
  })
  finishDate: Date;

  @Column({
    nullable: true,
    comment: "ทุน",
    length: 1000,
    default: null,
  })
  fundName: string;

  @Column({
    nullable: true,
    comment: "เกรดเฉลี่ย",
    length: 20,
    default: null,
  })
  gpa: string;

  @Column({
    nullable: true,
    comment: "สถานศึกษา",
    length: 1000,
    default: null,
  })
  institute: string;

  @Column({
    nullable: true,
    comment: "ข้อมูลการติดต่อ",
    length: 1000,
    default: null,
  })
  other: string;

  @Column({
    nullable: true,
    type: "datetime",
    comment: "ตั้งแต่",
    default: null,
  })
  startDate: Date;

  @Column({
    nullable: true,
    type: "datetime",
    comment: "ถึง",
    default: null,
  })
  endDate: Date;

  @Column({
    nullable: true,
    comment: "ระดับศึกษา",
    type: "text", // ใช้ "text" แทน "string" เพื่อรองรับ long text
    default: null,
  })
  educationLevel: string;

  @Column({
    nullable: true,
    length: 40,
    comment: "Id ระดับศึกษา",
    default: null,
  })
  educationLevelId: string;

  @Column({
    nullable: true,
    comment: "เป็นวุฒิการศึกษาในตำแหน่ง",
    type: "text",
    default: null,
  })
  positionPath: string;

  @Column({
    nullable: true,
    length: 40,
    comment: "Id เป็นวุฒิการศึกษาในตำแหน่ง",
    default: null,
  })
  positionPathId: string;

  @Column({
    nullable: true,
    comment: "ประเภทช่วงเวลาการศึกษา",
    default: null,
  })
  isDate: boolean;

  @Column({
    nullable: true,
    comment: "เป็นวุฒิศึกษาในตำแหน่ง",
    default: null,
  })
  isEducation: boolean;

  @Column({
    nullable: true,
    comment: "เป็นวุฒิศึกษาสูงสุด",
    default: null,
  })
  isHigh: boolean;

  @Column({
    nullable: true,
    comment: "หมายเหตุ",
    default: null,
  })
  note: string;

  @Column({
    nullable: true,
    length: 40,
    comment: "คีย์นอก(FK)ของตาราง Profile",
    default: null,
  })
  profileEducationId: string;

  @Column({
    nullable: false,
    comment: "สถานะลบข้อมูล",
    default: false,
  })
  isDeleted: boolean;

  @ManyToOne(
    () => ProfileEducation,
    (profileEducation) => profileEducation.profileEducationHistories,
  )
  @JoinColumn({ name: "profileEducationId" })
  histories: ProfileEducation;
}

export class CreateProfileEducationHistory {
  @Column()
  country: string | null;

  @Column()
  degree: string | null;

  @Column()
  duration: string | null;

  @Column()
  durationYear: number;

  @Column()
  field: string | null;

  @Column()
  finishDate: Date | null;

  @Column()
  fundName: string | null;

  @Column()
  gpa: string | null;

  @Column()
  institute: string | null;

  @Column()
  other: string | null;

  @Column()
  startDate: Date | null;

  @Column()
  endDate: Date | null;

  @Column()
  educationLevel: string | null;

  @Column("uuid")
  educationLevelId: string | null;

  @Column()
  positionPath: string | null;

  @Column("uuid")
  positionPathId: string | null;

  @Column()
  isDate: boolean | null;

  @Column()
  isEducation: boolean | null;

  @Column()
  isHigh?: boolean | null;

  @Column("uuid")
  profileEducationId: string | null;

  @Column()
  note: string | null;
}

export type UpdateProfileEducationHistory = Partial<CreateProfileEducationHistory>;
