package clock

import (
	"context"
	"fmt"
	"time"

	"github.com/enmanuel/agents/tools"
)

// NewCurrentTime creates a current_time tool that returns the current date and time.
// Useful for agents that need temporal awareness.
func NewCurrentTime() tools.Tool {
	return tools.Tool{
		Def: tools.Def{
			Name:        "current_time",
			Description: "Returns the current date and time in the server's timezone. Use this when you need to know the current time or date.",
			Parameters: []tools.Param{
				{Name: "format", Type: "string", Description: "Optional Go time format string. Defaults to RFC3339 if empty.", Required: false},
			},
		},
		Exec: func(ctx context.Context, args map[string]any) tools.Result {
			layout := tools.GetString(args, "format")
			if layout == "" {
				layout = time.RFC3339
			}

			now := time.Now()
			output := fmt.Sprintf("Current time: %s\nTimezone: %s", now.Format(layout), now.Location().String())
			return tools.Result{Output: output}
		},
	}
}
