import { Entity, Column, ManyToOne, JoinColumn } from "typeorm";
import { EntityBase } from "./base/Base";
import { ProfileEmployee } from "./ProfileEmployee";
import { AbsentLateStatus, StampType } from "./ProfileAbsentLate";

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

  @Column({
    type: "enum",
    enum: AbsentLateStatus,
    comment: "สถานะ มาสาย/ขาดราชการ",
    nullable: false,
  })
  status: AbsentLateStatus;

  @Column({
    type: "datetime",
    comment: "วันที่และเวลาที่ลงเวลา",
    nullable: false,
  })
  stampDate: Date;

  @Column({
    type: "enum",
    enum: StampType,
    comment: "เต็มวัน/ครึ่งเช้า/ครึ่งบ่าย",
    default: StampType.FULL_DAY,
  })
  stampType: StampType;

  @Column({
    type: "decimal",
    precision: 2,
    scale: 1,
    comment: "จำนวน (1.0/0.5)",
    default: "1.0",
  })
  stampAmount: number;

  @Column({
    type: "varchar",
    length: 250,
    comment: "หมายเหตุ",
    nullable: true,
  })
  remark: string;

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

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

// DTO Classes
export class CreateProfileEmployeeAbsentLate {
  profileEmployeeId: string;
  status: AbsentLateStatus;
  stampDate: Date;
  stampType?: StampType;
  stampAmount?: number;
  remark?: string;
}

export class CreateProfileEmployeeAbsentLateBatch {
  records: CreateProfileEmployeeAbsentLate[];
}

export type UpdateProfileEmployeeAbsentLate = {
  status?: AbsentLateStatus;
  stampDate?: Date;
  stampType?: StampType;
  stampAmount?: number;
  remark?: string;
};
