import { Column, Entity, JoinColumn, ManyToOne, Relation} from "typeorm";
import { AbstractEntity } from "./AbstractEntity.js";
import { RecipeEntity } from "./RecipeEntity.js";

/**
 * Entity describing an instruction step for a recipe
 */
@Entity({ name: "recipe_instruction_step" })
export class RecipeInstructionStepEntity extends AbstractEntity {
    @Column({ nullable: false })
    text!: string;

    @Column({ name: "sort_order", nullable: false })
    sortOrder!: number;

    @JoinColumn({name: "recipe_id"})
    @ManyToOne(() => RecipeEntity, (recipe) => recipe.instructionSteps,
    {
        onDelete: "CASCADE", 
        nullable: false,
        orphanedRowAction: "delete" // delete removed groups
    }
    )
    recipe!: Relation<RecipeEntity>;
    
}