import { Entity, Column, ManyToOne, JoinColumn, OneToMany } from "typeorm";
import { EntityBase } from "./base/Base";
import { Profile } from "./Profile";
import { ProfileEmployee } from "./ProfileEmployee";
import { ProfileAssessmentHistory } from "./ProfileAssessmentHistory";

@Entity("profileAssessment")
export class ProfileAssessment extends EntityBase {
  @Column({
    nullable: true,
    length: 40,
    comment: "คีย์นอก(FK)ของตาราง Profile",
    default: null,
  })
  profileId: string;

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

  @Column({
    nullable: true,
    comment: "ชื่อแบบประเมิน",
    type: "text",
    default: null,
  })
  name: string;

  @Column({
    nullable: true,
    comment: "รอบการประเมิน",
    length: 255,
    default: null,
  })
  period: string;

  @Column({
    comment: "ปีการประเมิน",
    nullable: true,
  })
  year: string;

  @Column({
    nullable: true,
    type: "datetime",
    comment: "วันที่ได้รับ",
    default: null,
  })
  date: Date;

  @Column({
    nullable: true,
    type: "double",
    comment: "ผลประเมินส่วนที่1 (คะแนน)",
    default: null,
  })
  point1: number;

  @Column({
    nullable: true,
    type: "double",
    comment: "ส่วนที่1 (คะแนน)",
    default: null,
  })
  point1Total: number;

  @Column({
    nullable: true,
    type: "double",
    comment: "ผลประเมินส่วนที่2 (คะแนน)",
    default: null,
  })
  point2: number;

  @Column({
    nullable: true,
    type: "double",
    comment: "ส่วนที่2 (คะแนน)",
    default: null,
  })
  point2Total: number;

  @Column({
    nullable: true,
    type: "double",
    comment: "ผลประเมินรวม (คะแนน)",
    default: null,
  })
  pointSum: number;

  @Column({
    nullable: true,
    type: "double",
    comment: "ผลรวม (คะแนน)",
    default: null,
  })
  pointSumTotal: number;

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

  @OneToMany(
    () => ProfileAssessmentHistory,
    (profileAssessmentHistory) => profileAssessmentHistory.histories,
  )
  profileAssessmentHistorys: ProfileAssessmentHistory[];

  @ManyToOne(() => Profile, (profile) => profile.profileAssessments)
  @JoinColumn({ name: "profileId" })
  profile: Profile;

  @ManyToOne(() => ProfileEmployee, (ProfileEmployee) => ProfileEmployee.profileAssessments)
  @JoinColumn({ name: "profileEmployeeId" })
  profileEmployee: ProfileEmployee;
}

export class CreateProfileAssessment {
  profileId: string | null;
  name: string | null;
  period: string | null;
  year: number | null;
  date: Date | null;
  point1: number | null;
  point1Total: number | null;
  point2: number | null;
  point2Total: number | null;
  pointSum: number | null;
  pointSumTotal: number | null;
}

export class CreateProfileEmployeeAssessment {
  profileEmployeeId: string | null;
  name: string | null;
  period: string | null;
  year: number | null;
  date: Date | null;
  point1: number | null;
  point1Total: number | null;
  point2: number | null;
  point2Total: number | null;
  pointSum: number | null;
  pointSumTotal: number | null;
}

export type UpdateProfileAssessment = {
  name?: string | null;
  period?: string | null;
  year?: number | null;
  date?: Date | null;
  point1?: number | null;
  point1Total?: number | null;
  point2?: number | null;
  point2Total?: number | null;
  pointSum?: number | null;
  pointSumTotal?: number | null;
};
