import {
  Entity,
  PrimaryGeneratedColumn,
  Column,
  ManyToOne,
  JoinColumn,
  Index,
} from "typeorm"
import { BaseEntity } from "../../common/entities/base.entity"
import { Company } from "../../company/entities/company.entity"
import { Employee } from "../../employees/entities/employee.entity"
import { Department } from "../../departments/entities/department.entity"

@Entity("salary_structures")
@Index(["employee_id", "effective_from", "effective_to"])
@Index(["company_id", "employee_id"])
export class SalaryStructure extends BaseEntity {
  @PrimaryGeneratedColumn()
  id: number

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

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

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

  @Column({ type: "date", nullable: false })
  effective_from: Date

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

  @Column({
    type: "smallint",
    default: 1,
    comment: "1=Active, 0=Inactive",
  })
  status: number

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

  @ManyToOne(() => Employee)
  @JoinColumn({ name: "employee_id" })
  employee: Employee

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