import {
  Entity,
  PrimaryGeneratedColumn,
  Column,
  OneToOne,
  JoinColumn,
  AfterLoad,
} from "typeorm"
import { BaseEntity } from "../../common/entities/base.entity"
import { Employee } from "./employee.entity"
import { isEmpty } from "class-validator"

@Entity("employee_information")
export class EmployeeInformation extends BaseEntity {
  @PrimaryGeneratedColumn()
  id: number

  @Column({ type: "int", nullable: false })
  employee_id: number

  @Column({ type: "text", nullable: false })
  address: string

  @Column({ type: "varchar", length: 10, nullable: false })
  gender: string

  @Column({ type: "varchar", length: 20, nullable: false })
  alternate_mobile_number: string

  @Column({ type: "date", nullable: true })
  date_of_birth: Date

  @Column({ type: "varchar", length: 20, nullable: true })
  marital_status: string

  @Column({ type: "varchar", length: 255, nullable: true })
  parents_name: string

  @Column({ type: "varchar", length: 20, nullable: true })
  parents_contact_number: string

  @Column({ type: "varchar", length: 10, nullable: true })
  blood_group: string

  @Column({ type: "varchar", length: 255, nullable: true })
  native_place: string

  @Column({ type: "varchar", length: 500, nullable: true })
  resume_url: string

  @Column({ type: "varchar", length: 20, nullable: true })
  aadhar_card: string

  @Column({ type: "varchar", length: 20, nullable: true })
  pan_card_number: string

  @Column({ type: "varchar", length: 255, nullable: true })
  education_qualification: string

  @Column({ type: "decimal", precision: 4, scale: 1, nullable: true })
  total_work_experience_years: number

  @OneToOne(() => Employee, (employee) => employee.employeeInformation)
  @JoinColumn({ name: "employee_id" })
  employee: Employee

  @AfterLoad()
  async setResumeUrl() {
    if (!isEmpty(this.resume_url)) {
      this.resume_url = process.env.BASE_URL + this.resume_url
    }
  }
}
