import {
  Column,
  CreateDateColumn,
  DeleteDateColumn,
  Entity,
  JoinTable,
  ManyToMany,
  ManyToOne,
  PrimaryGeneratedColumn,
  UpdateDateColumn,
} from 'typeorm'
import { Sku } from './sku'
import { Course } from './course'
import { User } from 'src/user/entities/user.entity'

@Entity()
export class CourseClass {
  @PrimaryGeneratedColumn()
  id: number

  @ManyToOne(() => Sku, (sku) => sku.courseClasses)
  sku: Sku

  @ManyToOne(() => Course, (course) => course.courseClasses)
  course: Course

  @Column({ default: 0 })
  moodle: number

  @Column()
  vacancies: number

  @Column({ nullable: true })
  begin: Date

  @Column({ nullable: true })
  end: Date

  @Column({ default: '' })
  dateFormated: string

  @Column({ default: 0, nullable: true })
  placeId: number

  @Column({ default: '' })
  place: string

  @Column()
  classNote: string

  @Column({ default: false })
  classConfirmed: boolean

  @Column({ default: false })
  moodleIntegrated: boolean

  @CreateDateColumn({
    type: 'timestamp',
    default: () => 'CURRENT_TIMESTAMP(6)',
    name: 'created_at',
  })
  createdAt: Date

  @UpdateDateColumn({
    type: 'timestamp',
    default: () => 'CURRENT_TIMESTAMP(6)',
    onUpdate: 'CURRENT_TIMESTAMP(6)',
    name: 'updated_at',
  })
  updatedAt: Date

  @DeleteDateColumn({ name: 'deleted_at', type: 'timestamp' })
  deletedAt?: Date

  @ManyToMany(() => User, (user) => user.coursesStudents)
  @JoinTable()
  students: User[]
}
