import {
  Entity,
  PrimaryGeneratedColumn,
  Column,
  ManyToOne,
  JoinColumn,
} from "typeorm"
import { BaseEntity } from "../../common/entities/base.entity"
import { MisBusinessKpis } from "./mis-business-kpis.entity"
import { MisReportRatingFeedback } from "./mis-report-rating-feedback.entity"
import { Employee } from "../../employees/entities/employee.entity"
import { Department } from "../../departments/entities/department.entity"
import { decimalTransformer } from "../../../utils/helpers"

@Entity("business_kpis_ratings")
export class BusinessKpiRating extends BaseEntity {
  @PrimaryGeneratedColumn()
  id: number

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

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

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

  @Column({
    type: "decimal",
    precision: 3,
    scale: 2,
    nullable: false,
    default: 0,
    transformer: decimalTransformer,
  })
  rating: number

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

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

  @Column({ type: "smallint", nullable: false })
  month: number

  @Column({ type: "smallint", nullable: false })
  year: number

  @ManyToOne(() => MisBusinessKpis)
  @JoinColumn({ name: "kpi_id" })
  kpi: MisBusinessKpis

  @ManyToOne(() => MisReportRatingFeedback)
  @JoinColumn({ name: "rating_id" })
  ratingFeedback: MisReportRatingFeedback

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

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

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