import {
  Entity,
  PrimaryGeneratedColumn,
  Column,
  CreateDateColumn,
  ManyToOne,
  JoinColumn,
  Unique,
} from 'typeorm';
import { Class } from './class.entity';
import { User } from './user.entity';

export enum TeacherRoleType {
  SUBJECT_TEACHER = 'subject_teacher',
  HEAD_TEACHER = 'head_teacher',
  LIFE_TEACHER = 'life_teacher',
  ACADEMIC_TEACHER = 'academic_teacher',
}

@Entity('class_teacher')
@Unique(['classId', 'userId', 'roleType'])
export class ClassTeacher {
  @PrimaryGeneratedColumn()
  id: number;

  @Column({ name: 'class_id', type: 'integer' })
  classId: number;

  @ManyToOne(() => Class, { onDelete: 'CASCADE' })
  @JoinColumn({ name: 'class_id' })
  class: Class;

  @Column({ name: 'user_id', type: 'integer' })
  userId: number;

  @ManyToOne(() => User, { onDelete: 'CASCADE' })
  @JoinColumn({ name: 'user_id' })
  user: User;

  @Column({ name: 'role_type', length: 30 })
  roleType: string;

  @Column({ name: 'subject', length: 50, nullable: true })
  subject: string;

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