package dto

import "time"

// AgentRuntimeFailureSummary is the API wire summary of the latest runtime failure.
type AgentRuntimeFailureSummary struct {
	EventClass string    `json:"eventClass"`
	MessageID  string    `json:"messageId,omitempty"`
	Summary    string    `json:"summary"`
	Detail     string    `json:"detail,omitempty"`
	OccurredAt time.Time `json:"occurredAt"`
}

// AppAgentInstance describes the current runtime instance of an app agent.
type AppAgentInstance struct {
	ID             string    `json:"id"`
	MachineID      string    `json:"machineId"`
	SessionID      string    `json:"sessionId"`
	Status         string    `json:"status"`
	Activity       string    `json:"activity"`
	ActivityDetail string    `json:"activityDetail"`
	SourceKind     string    `json:"sourceKind,omitempty"`
	SourceRef      string    `json:"sourceRef,omitempty"`
	StartedAt      time.Time `json:"startedAt"`
	LastSeenAt     time.Time `json:"lastSeenAt"`
}

// AgentRuntimeSnapshotsRequest requests bounded runtime rows for visible agents.
type AgentRuntimeSnapshotsRequest struct {
	AgentIDs []string `json:"agentIds"`
}

// AgentRuntimeSnapshot is the lightweight browser-facing runtime state for one agent.
type AgentRuntimeSnapshot struct {
	AgentID         string            `json:"agentId"`
	MachineID       string            `json:"machineId"`
	MachineStatus   string            `json:"machineStatus,omitempty"`
	AutoWakeEnabled bool              `json:"autoWakeEnabled"`
	Status          string            `json:"status"`
	Activity        string            `json:"activity"`
	ActivityDetail  string            `json:"activityDetail"`
	CurrentInstance *AppAgentInstance `json:"currentInstance,omitempty"`
}

// AgentRuntimeSnapshotsResponse returns bounded runtime rows.
type AgentRuntimeSnapshotsResponse struct {
	Snapshots []AgentRuntimeSnapshot `json:"snapshots"`
}

// AgentRoleBindingSummary describes the canonical Role version active for an agent.
type AgentRoleBindingSummary struct {
	BindingKind           string `json:"bindingKind,omitempty"`
	RoleID                string `json:"roleId,omitempty"`
	RoleVersionID         string `json:"roleVersionId,omitempty"`
	SourcePresetRoleID    string `json:"sourcePresetRoleId,omitempty"`
	SourcePresetVersionID string `json:"sourcePresetVersionId,omitempty"`
	ActiveDefinitionPath  string `json:"activeDefinitionPath,omitempty"`
	RealizationID         string `json:"realizationId,omitempty"`
}

// AppAgent is the agent shape expected by the web app client.
type AppAgent struct {
	ID                   string                      `json:"id"`
	Name                 string                      `json:"name"`
	MemberID             string                      `json:"memberId,omitempty"`
	OwnerUserID          string                      `json:"ownerUserId,omitempty"`
	DisplayName          string                      `json:"displayName,omitempty"`
	AvatarURL            string                      `json:"avatarUrl,omitempty"`
	Description          string                      `json:"description,omitempty"`
	Runtime              string                      `json:"runtime"`
	PermissionMode       string                      `json:"permissionMode"`
	Model                string                      `json:"model"`
	ReasoningEffort      string                      `json:"reasoningEffort,omitempty"`
	LLMMode              string                      `json:"llmMode,omitempty"`
	BaseURL              string                      `json:"baseUrl,omitempty"`
	Headers              map[string]string           `json:"headers,omitempty"`
	WireAPI              string                      `json:"wireApi,omitempty"`
	APIKeyConfigured     bool                        `json:"apiKeyConfigured,omitempty"`
	LLMConfigError       string                      `json:"llmConfigError,omitempty"`
	ModelProfileID       string                      `json:"modelProfileId,omitempty"`
	MachineID            string                      `json:"machineId"`
	MachineStatus        string                      `json:"machineStatus,omitempty"`
	SourceKind           string                      `json:"sourceKind,omitempty"`
	SourceRef            string                      `json:"sourceRef,omitempty"`
	CurrentRoleBinding   *AgentRoleBindingSummary    `json:"currentRoleBinding,omitempty"`
	CanManage            bool                        `json:"canManage"`
	CanReview            bool                        `json:"canReview"`
	CanDisable           bool                        `json:"canDisable"`
	AutoWakeEnabled      bool                        `json:"autoWakeEnabled"`
	Status               string                      `json:"status"`
	Activity             string                      `json:"activity"`
	ActivityDetail       string                      `json:"activityDetail"`
	CurrentInstance      *AppAgentInstance           `json:"currentInstance,omitempty"`
	CreatedAt            time.Time                   `json:"createdAt"`
	LatestRuntimeFailure *AgentRuntimeFailureSummary `json:"latestRuntimeFailure,omitempty"`
}
