package dto

import "time"

// WebAgentCreateRequest creates a browser-managed workspace agent.
type WebAgentCreateRequest struct {
	Name            string            `json:"name"`
	Description     string            `json:"description"`
	Runtime         string            `json:"runtime"`
	Model           string            `json:"model"`
	ReasoningEffort string            `json:"reasoningEffort"`
	LLMMode         string            `json:"llmMode,omitempty"`
	BaseURL         string            `json:"baseUrl,omitempty"`
	APIKey          string            `json:"apiKey,omitempty"`
	Headers         map[string]string `json:"headers,omitempty"`
	WireAPI         string            `json:"wireApi,omitempty"`
	ModelProfileID  string            `json:"modelProfileId,omitempty"`
	MachineID       string            `json:"machineId"`
	ChannelIDs      []string          `json:"channelIds,omitempty"`
}

// WebAgentDuplicateRequest duplicates a caller-managed workspace agent.
type WebAgentDuplicateRequest struct {
	Mode        string   `json:"mode,omitempty"`
	Name        string   `json:"name,omitempty"`
	DisplayName string   `json:"displayName,omitempty"`
	MachineID   string   `json:"machineId,omitempty"`
	Runtime     string   `json:"runtime,omitempty"`
	ChannelIDs  []string `json:"channelIds,omitempty"`
}

// WebAgentResourceCopyResponse summarizes resources copied during duplication.
type WebAgentResourceCopyResponse struct {
	Skills         int  `json:"skills"`
	KnowledgeBases int  `json:"knowledgeBases"`
	Memory         bool `json:"memory"`
}

// AgentMemorySyncStatusResponse is the browser-facing projection of one
// daemon-local Memory synchronization state.
type AgentMemorySyncStatusResponse struct {
	State   string    `json:"state"`
	Reason  string    `json:"reason,omitempty"`
	RetryAt time.Time `json:"retryAt,omitzero"`
}

// AgentMemorySyncRetryResponse reports whether the daemon accepted a manual
// Memory synchronization retry.
type AgentMemorySyncRetryResponse struct {
	RetryRequested bool `json:"retryRequested"`
}

// WebAgentDuplicateResponse returns the duplicated agent and optional resource
// copy summary.
type WebAgentDuplicateResponse struct {
	Agent        AppAgent                      `json:"agent"`
	ResourceCopy *WebAgentResourceCopyResponse `json:"resourceCopy,omitempty"`
}

// WebAgentUpdateRequest updates browser-managed agent metadata/runtime config.
type WebAgentUpdateRequest struct {
	Name            *string           `json:"name"`
	DisplayName     *string           `json:"displayName"`
	DeriveName      bool              `json:"deriveName"`
	Description     OptionalString    `json:"description"`
	AvatarURL       OptionalString    `json:"avatarUrl"`
	Runtime         *string           `json:"runtime"`
	PermissionMode  OptionalString    `json:"permissionMode"`
	Model           OptionalString    `json:"model"`
	ReasoningEffort OptionalString    `json:"reasoningEffort"`
	LLMMode         OptionalString    `json:"llmMode"`
	BaseURL         OptionalString    `json:"baseUrl"`
	APIKey          OptionalString    `json:"apiKey"`
	Headers         OptionalStringMap `json:"headers"`
	WireAPI         OptionalString    `json:"wireApi"`
	ModelProfileID  OptionalString    `json:"modelProfileId"`
}

// ModelProfile stores one user-owned reusable local runtime configuration.
type ModelProfile struct {
	ID               string    `json:"id"`
	ProviderID       string    `json:"providerId,omitempty"`
	DisplayName      string    `json:"displayName"`
	Model            string    `json:"model"`
	BaseURL          string    `json:"baseUrl,omitempty"`
	APIKey           string    `json:"apiKey,omitempty"`
	WireAPI          string    `json:"wireApi,omitempty"`
	APIKeyConfigured bool      `json:"apiKeyConfigured,omitempty"`
	CreatedAt        time.Time `json:"createdAt"`
	UpdatedAt        time.Time `json:"updatedAt"`
}

// ModelProfileCreateRequest creates one current-user model profile.
type ModelProfileCreateRequest struct {
	DisplayName string   `json:"displayName"`
	Models      []string `json:"models"`
	Model       string   `json:"model"`
	BaseURL     string   `json:"baseUrl"`
	APIKey      string   `json:"apiKey"`
	WireAPI     string   `json:"wireApi"`
}

// ModelProfileUpdateRequest updates one current-user model profile provider.
type ModelProfileUpdateRequest struct {
	DisplayName string   `json:"displayName"`
	Models      []string `json:"models"`
	Model       string   `json:"model"`
	BaseURL     string   `json:"baseUrl"`
	APIKey      string   `json:"apiKey"`
	WireAPI     string   `json:"wireApi"`
}

// ModelProfileModelsRequest detects model IDs for one ad-hoc upstream config.
type ModelProfileModelsRequest struct {
	BaseURL string `json:"baseUrl"`
	APIKey  string `json:"apiKey"`
	WireAPI string `json:"wireApi"`
}

// ModelProfileModelsResponse returns detected upstream model IDs.
type ModelProfileModelsResponse struct {
	Models []string `json:"models"`
}

// ModelProfileConnectionTestRequest tests one ad-hoc upstream config by sending
// a minimal non-streaming model request through the selected wire API.
type ModelProfileConnectionTestRequest struct {
	BaseURL string `json:"baseUrl"`
	APIKey  string `json:"apiKey"`
	WireAPI string `json:"wireApi"`
	Model   string `json:"model"`
}

// WebAgentResetRequest resets runtime/session state for an agent.
type WebAgentResetRequest struct {
	ClearWorkspace bool `json:"clearWorkspace"`
}
