// Package agentidp provides a Go client for the SentryAgent.ai AgentIdP API.
// It covers all 14 endpoints across agent registry, credential management,
// OAuth 2.0 token operations, and audit log queries.
package agentidp

// Agent is a registered AI agent identity.
type Agent struct {
	AgentID       string   `json:"agentId"`
	Email         string   `json:"email"`
	AgentType     string   `json:"agentType"`
	Version       string   `json:"version"`
	Capabilities  []string `json:"capabilities"`
	Owner         string   `json:"owner"`
	DeploymentEnv string   `json:"deploymentEnv"`
	Status        string   `json:"status"`
	CreatedAt     string   `json:"createdAt"`
	UpdatedAt     string   `json:"updatedAt"`
}

// RegisterAgentRequest is the body for POST /api/v1/agents.
type RegisterAgentRequest struct {
	Email         string   `json:"email"`
	AgentType     string   `json:"agentType"`
	Version       string   `json:"version"`
	Capabilities  []string `json:"capabilities"`
	Owner         string   `json:"owner"`
	DeploymentEnv string   `json:"deploymentEnv"`
}

// UpdateAgentRequest is the body for PATCH /api/v1/agents/:id.
// All fields are optional — only non-nil pointer fields are sent.
type UpdateAgentRequest struct {
	AgentType     *string  `json:"agentType,omitempty"`
	Version       *string  `json:"version,omitempty"`
	Capabilities  []string `json:"capabilities,omitempty"`
	Owner         *string  `json:"owner,omitempty"`
	DeploymentEnv *string  `json:"deploymentEnv,omitempty"`
	Status        *string  `json:"status,omitempty"`
}

// PaginatedAgents is a paginated list of agents.
type PaginatedAgents struct {
	Data  []Agent `json:"data"`
	Total int     `json:"total"`
	Page  int     `json:"page"`
	Limit int     `json:"limit"`
}

// ListAgentsParams contains optional query parameters for ListAgents.
type ListAgentsParams struct {
	Status        string
	AgentType     string
	DeploymentEnv string
	Page          int
	Limit         int
}

// Credential is a credential record (ClientSecret is never included).
type Credential struct {
	CredentialID string  `json:"credentialId"`
	ClientID     string  `json:"clientId"`
	Status       string  `json:"status"`
	CreatedAt    string  `json:"createdAt"`
	ExpiresAt    *string `json:"expiresAt"`
	RevokedAt    *string `json:"revokedAt"`
}

// CredentialWithSecret is a Credential with a one-time plaintext secret.
// Returned only on credential creation and rotation.
type CredentialWithSecret struct {
	Credential
	ClientSecret string `json:"clientSecret"`
}

// PaginatedCredentials is a paginated list of credentials.
type PaginatedCredentials struct {
	Data  []Credential `json:"data"`
	Total int          `json:"total"`
	Page  int          `json:"page"`
	Limit int          `json:"limit"`
}

// TokenResponse is the OAuth 2.0 access token response (RFC 6749).
type TokenResponse struct {
	AccessToken string `json:"access_token"`
	TokenType   string `json:"token_type"`
	ExpiresIn   int    `json:"expires_in"`
	Scope       string `json:"scope"`
}

// IntrospectResponse is the token introspection response (RFC 7662).
type IntrospectResponse struct {
	Active    bool    `json:"active"`
	Sub       *string `json:"sub,omitempty"`
	ClientID  *string `json:"client_id,omitempty"`
	Scope     *string `json:"scope,omitempty"`
	TokenType *string `json:"token_type,omitempty"`
	Iat       *int64  `json:"iat,omitempty"`
	Exp       *int64  `json:"exp,omitempty"`
}

// AuditEvent is an immutable audit event record.
type AuditEvent struct {
	EventID   string                 `json:"eventId"`
	AgentID   string                 `json:"agentId"`
	Action    string                 `json:"action"`
	Outcome   string                 `json:"outcome"`
	IPAddress string                 `json:"ipAddress"`
	UserAgent string                 `json:"userAgent"`
	Metadata  map[string]interface{} `json:"metadata"`
	Timestamp string                 `json:"timestamp"`
}

// PaginatedAuditEvents is a paginated list of audit events.
type PaginatedAuditEvents struct {
	Data  []AuditEvent `json:"data"`
	Total int          `json:"total"`
	Page  int          `json:"page"`
	Limit int          `json:"limit"`
}

// QueryAuditParams contains optional query parameters for QueryAuditLog.
type QueryAuditParams struct {
	AgentID  string
	Action   string
	Outcome  string
	FromDate string
	ToDate   string
	Page     int
	Limit    int
}
