// SPDX-FileCopyrightText: Amolith <amolith@secluded.site>
//
// SPDX-License-Identifier: LicenseRef-MutuaL-1.2

package mcp

import (
	"context"
	"testing"
)

// recipes.SAVE.2-3 tools.SAVE_RECIPE_TOOL.3
func TestCallToolACIDRecipesSave2_3DefaultsPreparedPortionsToOne(t *testing.T) {
	backend := &fakeBackend{saveRecipeID: testRecipeID}
	server := NewServer(backend, "test")

	_, output, err := server.callSaveRecipeTool(
		context.Background(),
		nil,
		SaveRecipeArguments{Source: "prepared", Title: "Pasta", Markdown: "# Pasta\n\n1. Boil pasta."},
	)
	if err != nil {
		t.Fatalf("callSaveRecipeTool() error = %v", err)
	}

	if backend.saveCalls != 1 {
		t.Fatalf("save calls = %d, want 1", backend.saveCalls)
	}
	if backend.savePortions != 1 {
		t.Fatalf("backend save portions = %g, want default 1", backend.savePortions)
	}
	if output.RecipeID != testRecipeID {
		t.Fatalf("save output recipe ID = %q, want test recipe ID", output.RecipeID)
	}
}

// recipes.SAVE.8-3 tools.SAVE_RECIPE_TOOL.6
func TestCallToolACIDRecipesSave8_3DefaultsExistingPortionsToOne(t *testing.T) {
	backend := &fakeBackend{}
	server := NewServer(backend, "test")

	_, output, err := server.callSaveRecipeTool(
		context.Background(),
		nil,
		SaveRecipeArguments{Source: "existing", RecipeID: testRecipeID, Markdown: "# Pasta\n\n1. Boil pasta."},
	)
	if err != nil {
		t.Fatalf("callSaveRecipeTool() error = %v", err)
	}

	if backend.updateCalls != 1 {
		t.Fatalf("update calls = %d, want 1", backend.updateCalls)
	}
	if backend.updatePortions != 1 {
		t.Fatalf("backend update portions = %g, want default 1", backend.updatePortions)
	}
	if output.RecipeID != testRecipeID {
		t.Fatalf("save output recipe ID = %q, want test recipe ID", output.RecipeID)
	}
}
