import {
  Entity,
  PrimaryGeneratedColumn,
  Column,
  ManyToOne,
  JoinColumn,
  OneToOne,
  OneToMany,
} from "typeorm"
import { BaseEntity } from "../../common/entities/base.entity"
import { Company } from "../../company/entities/company.entity"
import { Department } from "../../departments/entities/department.entity"
import { Role } from "../../role/entities/role.entity"
import { EmployeeInformation } from "./employee-information.entity"
import { EmployeeTechnologyAssignment } from "./employee-technology-assignment.entity"

@Entity("employees")
export class Employee extends BaseEntity {
  @PrimaryGeneratedColumn()
  id: number

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

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

  @Column({ type: "int", nullable: true })
  department_id: number

  @Column({ type: "int", nullable: true })
  sub_department_id: number

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

  @Column({ type: "int", nullable: true })
  team_lead_id: number

  @Column({ type: "varchar", length: 255, nullable: false })
  first_name: string

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

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

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

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

  @Column({ type: "timestamp", nullable: true })
  last_login_at: Date

  @Column({ type: "decimal", precision: 10, scale: 2, nullable: true })
  gross_salary: number

  @Column({ type: "decimal", precision: 10, scale: 2, nullable: true })
  basic_salary: number

  @Column({ type: "decimal", precision: 10, scale: 2, nullable: true })
  net_payable_salary: number

  @Column({ type: "decimal", precision: 10, scale: 2, nullable: true })
  tds_amount: number

  @Column({ type: "varchar", length: 50, nullable: false, default: "new" })
  regime_type: string

  @Column({ type: "varchar", length: 50, nullable: false, default: "employee" })
  employee_type: string

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

  @Column({ type: "int", nullable: true })
  probation_period: number

  @Column({ type: "int", nullable: true })
  notice_period: number

  @Column({ type: "decimal", precision: 10, scale: 2, nullable: true })
  stipend: number

  @Column({
    type: "smallint",
    default: 1,
  })
  status: number

  @ManyToOne(() => Company)
  @JoinColumn({ name: "company_id" })
  company: Company

  @ManyToOne(() => Department)
  @JoinColumn({ name: "department_id" })
  department: Department

  @ManyToOne(() => Department)
  @JoinColumn({ name: "sub_department_id" })
  subDepartment: Department

  @ManyToOne(() => Role)
  @JoinColumn({ name: "role_id" })
  role: Role

  @ManyToOne(() => Employee)
  @JoinColumn({ name: "team_lead_id" })
  teamLead: Employee

  @OneToOne(() => EmployeeInformation, (info) => info.employee)
  employeeInformation: EmployeeInformation

  @OneToMany(
    () => EmployeeTechnologyAssignment,
    (assignment) => assignment.employee,
  )
  technologyAssignments: EmployeeTechnologyAssignment[]
}
