import {
  Entity,
  PrimaryGeneratedColumn,
  Column,
  ManyToOne,
  JoinColumn,
  CreateDateColumn,
  Index,
} from 'typeorm';
import { AuditScheduleRow } from './audit-schedule-row.entity';
import { User } from '../../user/entities/user.entity';

@Entity({ name: 'audit_status_history' })
export class AuditStatusHistory {
  @PrimaryGeneratedColumn()
  id: number;

  @Index()
  @Column({ type: 'int' })
  row_id: number;

  @ManyToOne(() => AuditScheduleRow, { onDelete: 'CASCADE' })
  @JoinColumn({ name: 'row_id' })
  row: AuditScheduleRow;

  @Column({ type: 'varchar', length: 20, nullable: true })
  old_status: string;

  @Column({ type: 'varchar', length: 20 })
  new_status: string;

  @Column({ type: 'int', nullable: true })
  changed_by_id: number;

  @ManyToOne(() => User, { nullable: true })
  @JoinColumn({ name: 'changed_by_id' })
  changed_by: User;

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

  @Column({ type: 'text', nullable: true })
  notes: string;

  @CreateDateColumn()
  created_at: Date;
}
