import {
  Column,
  CreateDateColumn,
  Entity,
  Index,
  JoinColumn,
  ManyToOne,
  PrimaryGeneratedColumn,
  UpdateDateColumn,
} from 'typeorm';
import { Classroom } from './classroom.entity';

export enum AttendanceDeviceStatus {
  ACTIVE = 'active',
  DISABLED = 'disabled',
}

@Entity('attendance_devices')
@Index(['deviceSn'], { unique: true })
@Index(['classroomId'])
export class AttendanceDevice {
  @PrimaryGeneratedColumn()
  id: number;

  @Column({ name: 'device_sn', type: 'varchar', length: 100 })
  deviceSn: string;

  @Column({ name: 'device_name', type: 'varchar', length: 100 })
  deviceName: string;

  @Column({ name: 'classroom_id', type: 'integer' })
  classroomId: number;

  @ManyToOne(() => Classroom, { onDelete: 'CASCADE' })
  @JoinColumn({ name: 'classroom_id' })
  classroom: Classroom;

  @Column({ type: 'varchar', length: 20, default: AttendanceDeviceStatus.ACTIVE })
  status: AttendanceDeviceStatus | 'active' | 'disabled';

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

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

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

  @UpdateDateColumn({ name: 'updated_at' })
  updatedAt: Date;
}
