import { Entity, PrimaryGeneratedColumn, Column, ManyToOne, JoinColumn } from 'typeorm';
import { DecisionTree } from '../decision-trees/decision-tree.entity';

@Entity({ name: 'decision_tree_edges' })
export class DecisionTreeEdge {
  @PrimaryGeneratedColumn({ type: 'bigint' })
  id!: number;

  @Column({ type: 'bigint', name: 'tree_id' })
  treeId!: number;

  @ManyToOne(() => DecisionTree, (tree) => tree.edges, { onDelete: 'CASCADE' })
  @JoinColumn({ name: 'tree_id' })
  tree?: DecisionTree;

  @Column({ type: 'bigint', name: 'from_node_id' })
  fromNodeId!: number;

  @Column({ type: 'bigint', name: 'to_node_id' })
  toNodeId!: number;

  @Column({ type: 'varchar', length: 512, nullable: true })
  condition?: string;

  /** Option text shown to the learner for this branch. */
  @Column({ type: 'varchar', length: 255, nullable: true })
  label?: string;

  @Column({ name: 'order_index', type: 'int', default: 0 })
  orderIndex!: number;
}
