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

@Entity("notifications")
export class Notification extends BaseEntity {
  @PrimaryGeneratedColumn()
  id: number

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

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

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

  @Column({ type: "smallint", default: 0 })
  is_read: number

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

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

  // ====== RELATIONS ======

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

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