/**
 * IncidenteInvolucrado Entity
 * Personas involucradas en incidentes
 *
 * @module HSE
 * @table hse.incidente_involucrados
 * @ddl schemas/03-hse-schema-ddl.sql
 * @rf RF-MAA017-001
 */

import {
  Entity,
  PrimaryGeneratedColumn,
  Column,
  CreateDateColumn,
  ManyToOne,
  JoinColumn,
} from 'typeorm';
import { Incidente } from './incidente.entity';
import { Employee } from '../../hr/entities/employee.entity';

export type RolInvolucrado = 'lesionado' | 'testigo' | 'responsable';

@Entity({ schema: 'hse', name: 'incidente_involucrados' })
export class IncidenteInvolucrado {
  @PrimaryGeneratedColumn('uuid')
  id: string;

  @Column({ name: 'incidente_id', type: 'uuid' })
  incidenteId: string;

  @Column({ name: 'employee_id', type: 'uuid' })
  employeeId: string;

  @Column({ type: 'enum', enum: ['lesionado', 'testigo', 'responsable'] })
  rol: RolInvolucrado;

  @Column({ name: 'descripcion_lesion', type: 'text', nullable: true })
  descripcionLesion: string;

  @Column({ name: 'parte_cuerpo', type: 'varchar', length: 100, nullable: true })
  parteCuerpo: string;

  @Column({ name: 'dias_incapacidad', type: 'integer', default: 0 })
  diasIncapacidad: number;

  @CreateDateColumn({ name: 'created_at', type: 'timestamptz' })
  createdAt: Date;

  // Relations
  @ManyToOne(() => Incidente, (i) => i.involucrados, { onDelete: 'CASCADE' })
  @JoinColumn({ name: 'incidente_id' })
  incidente: Incidente;

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