/** * Recipes resource – Production BC. * Endpoints: POST /api/recipes, * POST /api/recipes/{id}/ingredients, * DELETE /api/recipes/{id}/ingredients/{ingredientId} */ import type { AxiosInstance } from 'axios'; import type { RecipeDTO, IngredientDTO, CreateRecipeRequest, AddRecipeIngredientRequest, } from '@effigenix/types'; export type RecipeType = 'RAW_MATERIAL' | 'INTERMEDIATE' | 'FINISHED_PRODUCT'; export type RecipeStatus = 'DRAFT' | 'ACTIVE' | 'ARCHIVED'; export const RECIPE_TYPE_LABELS: Record = { RAW_MATERIAL: 'Rohstoff', INTERMEDIATE: 'Halbfabrikat', FINISHED_PRODUCT: 'Fertigprodukt', }; export type { RecipeDTO, IngredientDTO, CreateRecipeRequest, AddRecipeIngredientRequest, }; // ── Resource factory ───────────────────────────────────────────────────────── const BASE = '/api/recipes'; export function createRecipesResource(client: AxiosInstance) { return { async list(): Promise { const res = await client.get(BASE); return res.data; }, async getById(id: string): Promise { const res = await client.get(`${BASE}/${id}`); return res.data; }, async create(request: CreateRecipeRequest): Promise { const res = await client.post(BASE, request); return res.data; }, async addIngredient(id: string, request: AddRecipeIngredientRequest): Promise { const res = await client.post(`${BASE}/${id}/ingredients`, request); return res.data; }, async removeIngredient(recipeId: string, ingredientId: string): Promise { await client.delete(`${BASE}/${recipeId}/ingredients/${ingredientId}`); const res = await client.get(`${BASE}/${recipeId}`); return res.data; }, }; } export type RecipesResource = ReturnType;