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

@Entity("profileOther")
export class ProfileOther 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,
  })
  detail: string;

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

  @Column({
    comment: "ข้อมูลจาก Entry",
    default: false,
  })
  isEntry: boolean;

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

  @OneToMany(() => ProfileOtherHistory, (profileOtherHistory) => profileOtherHistory.histories)
  profileOtherHistories: ProfileOtherHistory[];

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

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

export class CreateProfileOther {
  profileId: string | null;
  detail: string | null;
  date: Date | null;
}

export class CreateProfileEmployeeOther {
  profileEmployeeId: string | null;
  detail: string | null;
  date: Date | null;
}

export type UpdateProfileOther = {
  detail?: string | null;
  date?: Date | null;
};
