import {
  Entity,
  Column,
  PrimaryGeneratedColumn,
  ManyToOne,
  JoinColumn,
  CreateDateColumn,
  UpdateDateColumn,
} from 'typeorm';
import { Template } from './../../template/entities/template.entity';
import { User } from './../../user/entities/user.entity';

@Entity('template_contents')
export class TemplateContent {
  @PrimaryGeneratedColumn()
  id: number;

  // Relation to Template
  @ManyToOne(() => Template, (template) => template.contents, {
    onDelete: 'CASCADE',
  })
  @JoinColumn({ name: 'template_id' })
  template: Template;

  
  @Column()
  template_id: number; // foreign key reference

  @Column({ nullable: true })
  title: string;

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

  @Column({ type: 'time', nullable: true })
  startTime: string; // e.g., "09:00"

  @Column({ type: 'time', nullable: true })
  endTime: string; // e.g., "10:00"

  @Column({ nullable: true })
  functional_area: string; // e.g., "Production"

  // Relation to User who created this content
  @ManyToOne(() => User, { nullable: true })
  @JoinColumn({ name: 'created_by' })
  createdBy: User;

  @Column({ nullable: true })
  created_by: number;

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

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