import {
  Entity,
  PrimaryGeneratedColumn,
  Column,
  CreateDateColumn,
  UpdateDateColumn,
} from 'typeorm';

/**
 * Previous NC — main NC record from the legacy Laravel system.
 * One record per audit, contains parent metadata; child findings live
 * in ncr_entries and remarks in nc_remarks.
 *
 * Table exists in BOTH 'qrs' and 'tqs' databases with identical schema.
 * Connection is decided at injection time in the module.
 */
@Entity({ name: 'nc__ncs' })
export class PreviousNcEntity {
  @PrimaryGeneratedColumn({ type: 'bigint', unsigned: true })
  id: number;

  @Column({ type: 'int', nullable: true, unsigned: true })
  client_id: number | null;

  @Column({ type: 'int', nullable: true, unsigned: true })
  serve_id: number | null;

  @Column({ type: 'varchar', length: 255, nullable: true })
  auditee_name: string | null;

  @Column({ type: 'varchar', length: 255 })
  audit_type: string;

  @Column({ type: 'varchar', length: 255 })
  nc_type: string;

  @Column({ type: 'enum', enum: ['open', 'closed'] })
  status: 'open' | 'closed';

  @Column({ type: 'date', nullable: true })
  follow_up_date: string | null;

  @Column({ type: 'int', nullable: true, unsigned: true })
  followed_up_by: number | null;

  @Column({ type: 'text', nullable: true })
  final_closure_pdf: string | null;

  @Column({ type: 'text', nullable: true })
  follow_up_notes: string | null;

  @Column({ type: 'int', nullable: true, unsigned: true })
  closed_by: number | null;

  @Column({ type: 'datetime', nullable: true })
  closed_at: Date | null;

  @Column({ type: 'date', nullable: true })
  due_date: string | null;

  @Column({ type: 'text', nullable: true })
  remark: string | null;

  @CreateDateColumn({ type: 'timestamp' })
  created_at: Date;

  @UpdateDateColumn({ type: 'timestamp' })
  updated_at: Date;
}
