1// SPDX-FileCopyrightText: Amolith <amolith@secluded.site>
2//
3// SPDX-License-Identifier: LicenseRef-MutuaL-1.2
4
5package mcp
6
7import (
8 "context"
9
10 "git.secluded.site/cooked-mcp/internal/cooked"
11)
12
13const (
14 testRecipeID = "38f161dd-a514-4d5a-a924-0227695d9151"
15 testRecipeID2 = "38f161dd-a514-4d5a-a924-0227695d9152"
16 testOtherRecipeID = "8263f928-1111-4222-8333-123456789abc"
17 testDraftID = "aaaaaaaa-bbbb-4ccc-8ddd-eeeeeeeeeeee"
18 testProductGroupID = "11111111-2222-4333-8444-555555555555"
19 testProductGroupID2 = "66666666-7777-4888-9999-aaaaaaaaaaaa"
20 testProductGroupID3 = "77777777-8888-4999-aaaa-bbbbbbbbbbbb"
21 testProductGroupID4 = "88888888-9999-4aaa-bbbb-cccccccccccc"
22)
23
24type fakeBackend struct {
25 shoppingList cooked.ShoppingList
26 recipes []cooked.RecipeCard
27 recipesByPage map[int][]cooked.RecipeCard
28 searchRecipes []cooked.RecipeCard
29 recipeMetadata cooked.RecipeMetadata
30 recipeContent cooked.RecipeContent
31 preview cooked.RecipeTextPreview
32 importRecipeURLResult cooked.RecipeURLImport
33 saveRecipeID string
34 draftSaveRecipeID string
35 page int
36 limit int
37 searchQuery string
38 searchPage int
39 metadataRecipeID string
40 contentRecipeID string
41 previewTitle string
42 previewText string
43 importURL string
44 saveTitle string
45 saveMarkdown string
46 savePortions float64
47 draftSaveID string
48 draftSaveMarkdown string
49 draftSavePortions float64
50 updateRecipeID string
51 updateMarkdown string
52 updatePortions float64
53 deleteRecipeID string
54 addShoppingListResult cooked.AddShoppingListResult
55 addIngredients string
56 addRecipeID string
57 removeProductGroupIDs []string
58 replaceSelectionProductGroupIDs []string
59 updateShoppingListProductGroupID string
60 updateShoppingListProductGroup cooked.ShoppingListProductGroupUpdate
61 metadataCalls int
62 listRecipeCalls int
63 readShoppingListCalls int
64 contentCalls int
65 previewCalls int
66 importRecipeURLCalls int
67 saveCalls int
68 draftSaveCalls int
69 updateCalls int
70 deleteCalls int
71 clearShoppingListCalls int
72 addShoppingListCalls int
73 removeShoppingListCalls int
74 replaceSelectionCalls int
75 updateShoppingListCalls int
76}
77
78func (f *fakeBackend) ReadShoppingList(context.Context) (cooked.ShoppingList, error) {
79 f.readShoppingListCalls++
80
81 return f.shoppingList, nil
82}
83
84func (f *fakeBackend) ListRecipes(_ context.Context, page, limit int) ([]cooked.RecipeCard, error) {
85 f.page = page
86 f.limit = limit
87 f.listRecipeCalls++
88 if f.recipesByPage != nil {
89 return f.recipesByPage[page], nil
90 }
91
92 return f.recipes, nil
93}
94
95func (f *fakeBackend) SearchRecipes(_ context.Context, query string, page int) ([]cooked.RecipeCard, error) {
96 f.searchQuery = query
97 f.searchPage = page
98
99 return f.searchRecipes, nil
100}
101
102func (f *fakeBackend) ReadRecipeMetadata(_ context.Context, recipeID string) (cooked.RecipeMetadata, error) {
103 f.metadataRecipeID = recipeID
104 f.metadataCalls++
105
106 return f.recipeMetadata, nil
107}
108
109func (f *fakeBackend) ReadRecipeContent(_ context.Context, recipeID string) (cooked.RecipeContent, error) {
110 f.contentRecipeID = recipeID
111 f.contentCalls++
112
113 return f.recipeContent, nil
114}
115
116func (f *fakeBackend) PreviewRecipeText(_ context.Context, title, text string) (cooked.RecipeTextPreview, error) {
117 f.previewTitle = title
118 f.previewText = text
119 f.previewCalls++
120
121 return f.preview, nil
122}
123
124func (f *fakeBackend) SavePreparedRecipe(_ context.Context, title, markdown string, portions float64) (string, error) {
125 f.saveTitle = title
126 f.saveMarkdown = markdown
127 f.savePortions = portions
128 f.saveCalls++
129 if f.saveRecipeID != "" {
130 return f.saveRecipeID, nil
131 }
132
133 return testRecipeID, nil
134}
135
136func (f *fakeBackend) SaveRecipeDraft(_ context.Context, draftID, markdown string, portions float64) (string, error) {
137 f.draftSaveID = draftID
138 f.draftSaveMarkdown = markdown
139 f.draftSavePortions = portions
140 f.draftSaveCalls++
141 if f.draftSaveRecipeID != "" {
142 return f.draftSaveRecipeID, nil
143 }
144
145 return testRecipeID, nil
146}
147
148func (f *fakeBackend) UpdateRecipeContent(_ context.Context, recipeID, markdown string, portions float64) error {
149 f.updateRecipeID = recipeID
150 f.updateMarkdown = markdown
151 f.updatePortions = portions
152 f.updateCalls++
153
154 return nil
155}
156
157func (f *fakeBackend) ImportRecipeURL(_ context.Context, recipeURL string) (cooked.RecipeURLImport, error) {
158 f.importURL = recipeURL
159 f.importRecipeURLCalls++
160
161 return f.importRecipeURLResult, nil
162}
163
164func (f *fakeBackend) DeleteRecipe(_ context.Context, recipeID string) error {
165 f.deleteRecipeID = recipeID
166 f.deleteCalls++
167
168 return nil
169}
170
171func (f *fakeBackend) ClearShoppingList(context.Context) error {
172 f.clearShoppingListCalls++
173
174 return nil
175}
176
177func (f *fakeBackend) AddShoppingListIngredients(
178 _ context.Context,
179 ingredients, recipeID string,
180) (cooked.AddShoppingListResult, error) {
181 f.addIngredients = ingredients
182 f.addRecipeID = recipeID
183 f.addShoppingListCalls++
184
185 return f.addShoppingListResult, nil
186}
187
188func (f *fakeBackend) RemoveShoppingListProductGroups(_ context.Context, ids []string) error {
189 f.removeProductGroupIDs = ids
190 f.removeShoppingListCalls++
191
192 return nil
193}
194
195func (f *fakeBackend) ReplaceShoppingListSelection(_ context.Context, ids []string) error {
196 f.replaceSelectionProductGroupIDs = ids
197 f.replaceSelectionCalls++
198
199 return nil
200}
201
202func (f *fakeBackend) UpdateShoppingListProductGroup(
203 _ context.Context,
204 productGroupID string,
205 update cooked.ShoppingListProductGroupUpdate,
206) error {
207 f.updateShoppingListProductGroupID = productGroupID
208 f.updateShoppingListProductGroup = update
209 f.updateShoppingListCalls++
210
211 return nil
212}