// SPDX-FileCopyrightText: Amolith <amolith@secluded.site>
//
// SPDX-License-Identifier: AGPL-3.0-or-later

package shared

import (
	"errors"
	"fmt"

	"github.com/modelcontextprotocol/go-sdk/mcp"
)

// ErrorResult creates an MCP CallToolResult indicating an error.
// Use this for user-facing errors (validation failures, API errors, etc.).
// The Go error return should remain nil per MCP SDK conventions.
func ErrorResult(msg string) *mcp.CallToolResult {
	return &mcp.CallToolResult{
		IsError: true,
		Content: []mcp.Content{
			&mcp.TextContent{Text: msg},
		},
	}
}

// Estimate constraints.
const (
	MinEstimate = 0
	MaxEstimate = 720
)

// ErrInvalidEstimate indicates the estimate is out of range.
var ErrInvalidEstimate = errors.New("estimate must be between 0 and 720 minutes")

// ValidateEstimate checks that an estimate is within the valid range (0-720 minutes).
func ValidateEstimate(estimate int) error {
	if estimate < MinEstimate || estimate > MaxEstimate {
		return fmt.Errorf("%w: got %d", ErrInvalidEstimate, estimate)
	}

	return nil
}
