m&7i"ddZddlZddlmZmZddlmZejeZ GddZ y)zoRecipe Service - Business Logic for Recipe Operations. Handles recipe CRUD operations, search, and filtering. N)ListOptional)RecipeceZdZdZdZdededeefdZde de fdZ de de fd Z de deefd Z deefd Zd edeefd ZdeedeefdZd edeedeefdZddedee de fdZy) RecipeServicezService class for recipe business logic. This service layer provides a clean interface for UI components to interact with recipe data without directly accessing the database layer. c||_y)zhInitialize the recipe service. Args: db_manager: DatabaseManager instance. N) db_manager)selfr s B/mnt/ssd/data/python-lab/ChefSystem/src/services/recipe_service.py__init__zRecipeService.__init__s %name prompt_textreturnc h |r|jstjdy|r|jstjdytj|j |j||j dd|j dd|j dd}|r2tjd |jd |jd |Stjd |d |S#t$r$}tjd|dYd}~yd}~wwxYw)a%Create a new recipe. Args: name: Recipe name (must be unique). prompt_text: Prompt template text. **kwargs: Additional optional fields (tags, description, notes). Returns: Recipe instance if successful, None otherwise. z$Cannot create recipe with empty nameNz+Cannot create recipe with empty prompt texttags descriptionnotes)rrrrrzCreated recipe: z (ID: )zFailed to create recipe: z (likely duplicate name)zError creating recipe: Texc_info) striploggererrorrcreater getinforid Exception)r rrkwargsrecipees r create_recipezRecipeService.create_recipes tzz| CDk&7&7&9 JK]]ZZ\'ZZ+"JJ}b9jj"- F .v{{m6&))ANOM 8>VWXM  LL21#6L F s)'D'DBD)D D1 D,,D1 recipe_idc < |stjdyd|vrD|dr|djstjdy|dj|d<d|vr.|dr|djstjdyt j |j |fi|}|rtjd||Stjd||S#t$r'}tjd |d |d Yd }~yd }~wwxYw)aUpdate an existing recipe. Args: recipe_id: ID of recipe to update. **kwargs: Fields to update (name, prompt_text, tags, description, notes). Returns: bool: True if successful, False otherwise. zNo fields provided to updateFrz$Cannot update recipe with empty namerz+Cannot update recipe with empty prompt textzUpdated recipe ID zFailed to update recipe ID zError updating recipe : TrN) rwarningrrrupdater rr )r r%r!successr#s r update_recipezRecipeService.update_recipeGs =>f~VF^-A-A-CLL!GH !'!5!5!7v&m,F=4I4O4O4QLL!NO mmDOOYI&IG 0 <=N :9+FGN  LL1)BqcBTL R s/C+1C+ AC+QYZ [N  LLB1#FQUL VI sA!A$$ B-BBBN exclude_idcT |r|jsy|j}|D]O}|jj|jjk(s=||j|k(rOyy#t $r$}t jd|dYd}~yd}~wwxYw)aCheck if a recipe name is unique. Args: name: Recipe name to check. exclude_id: Optional recipe ID to exclude from check (for updates). Returns: bool: True if name is unique, False if already exists. FNTz Error checking name uniqueness: r)rr9rlowerrr rr)r rrB all_recipesr"r#s r check_name_uniquezRecipeService.check_name_uniques tzz|..0K% !;;$$&$**,*<*<*>>!-&))z2I   !  LL;A3?$L O s)A:AA:$A:8A:: B'B""B')N)__name__ __module__ __qualname____doc__r strrrr$intboolr+r/r3rr9r=r?rArFr r rr s %)#)C)hvFV)V)s))Vst0CHV,<. f CDL,49f,s$s)V 0cx}PTr r) rJloggingtypingrrsrc.database.modelsr getLoggerrGrrrNr r rSs3 !&   8 $DDr