import {
  Entity,
  PrimaryGeneratedColumn,
  Column,
  CreateDateColumn,
  ManyToOne,
  JoinColumn,
} from 'typeorm';
import { Exclude } from 'class-transformer';
import { Word } from './word.entity';

/**
 * Definition entity — one of potentially many definitions for a Word.
 * Each definition has an optional context (place, note, link, etc.).
 */
@Entity('definition')
export class Definition {
  @PrimaryGeneratedColumn('uuid')
  id!: string;

  /** The actual definition text */
  @Column({ type: 'text' })
  text!: string;

  /** Date the definition was recorded */
  @CreateDateColumn()
  date!: Date;

  /**
   * Optional context string.
   * May hold a location, note, URL, etc. (structured further in future iterations).
   */
  @Column({ type: 'text', nullable: true })
  context!: string | null;

  /** The word this definition belongs to — excluded from JSON to avoid circular refs */
  @Exclude()
  @ManyToOne(() => Word, (word) => word.definitions, { onDelete: 'CASCADE' })
  @JoinColumn({ name: 'word_id' })
  word!: Word;
}
