package registry

import (
	"time"
)

// Status is the lifecycle state of a registered agent.
type Status string

const (
	StatusActive   Status = "active"
	StatusInactive Status = "inactive"
	StatusRevoked  Status = "revoked"
)

// Agent is a lightweight registry record (who may call governed tools).
type Agent struct {
	AgentID     string         `json:"agent_id"`
	DisplayName string         `json:"display_name"`
	Roles       []string       `json:"roles,omitempty"`
	Tenant      string         `json:"tenant"`
	Status      Status         `json:"status"`
	Metadata    map[string]any `json:"metadata,omitempty"`
	CreatedAt   time.Time      `json:"created_at"`
	UpdatedAt   time.Time      `json:"updated_at"`
}

// UpsertRequest creates or replaces registry fields for an agent.
type UpsertRequest struct {
	AgentID     string         `json:"agent_id"`
	DisplayName string         `json:"display_name"`
	Roles       []string       `json:"roles,omitempty"`
	Tenant      string         `json:"tenant"`
	Status      Status         `json:"status"`
	Metadata    map[string]any `json:"metadata,omitempty"`
}

// PatchRequest updates selected fields.
type PatchRequest struct {
	DisplayName *string        `json:"display_name,omitempty"`
	Roles       []string       `json:"roles,omitempty"`
	Tenant      *string        `json:"tenant,omitempty"`
	Status      *Status        `json:"status,omitempty"`
	Metadata    map[string]any `json:"metadata,omitempty"`
}

// Repository stores registered agents.
type Repository interface {
	List(limit int) ([]Agent, error)
	Get(agentID string) (*Agent, error)
	Upsert(req UpsertRequest) (*Agent, error)
	Patch(agentID string, req PatchRequest) (*Agent, error)
}
