import { Column, Entity, ManyToMany } from "typeorm";
import { AbstractEntity } from "./AbstractEntity.js";
import { RecipeEntity } from "./RecipeEntity.js";

/**
 * Persisted tag that can be attached to any number of recipes.
 * The join table (recipe_tag) is owned by RecipeEntity.
 */
@Entity({ name: "tag" })
export class TagEntity extends AbstractEntity {
    @Column({ type: "varchar", length: 100, unique: true, nullable: false })
    description!: string;

    /**
     * Inverse side of the ManyToMany relation.
     * The join table is declared on RecipeEntity to keep ownership there.
     */
    @ManyToMany(() => RecipeEntity, recipe => recipe.tagList)
    recipeList!: RecipeEntity[];
}