package dto

import "time"

// --- Provider ---

// OrgProviderModel is the browser-facing provider model shape.
type OrgProviderModel struct {
	Name string `json:"name"`
	ID   string `json:"id"`
}

// OrgProviderEndpoints is the browser-facing provider endpoints shape.
type OrgProviderEndpoints struct {
	MessagesBaseURL   string `json:"messagesBaseUrl"`
	ResponsesBaseURL  string `json:"responsesBaseUrl"`
	EmbeddingsBaseURL string `json:"embeddingsBaseUrl"`
}

// OrgProviderCapabilities is the browser-facing provider capabilities shape.
type OrgProviderCapabilities struct {
	OpenAICompatible    bool `json:"openaiCompatible"`
	AnthropicCompatible bool `json:"anthropicCompatible"`
	ResponsesCompatible bool `json:"responsesCompatible"`
	EmbeddingCompatible bool `json:"embeddingCompatible"`
}

// OrgProviderView is the browser-facing organization provider definition.
type OrgProviderView struct {
	ID             string                  `json:"id"`
	OrganizationID string                  `json:"organizationId"`
	Name           string                  `json:"name"`
	Description    string                  `json:"description"`
	DriverKind     string                  `json:"driverKind"`
	ProviderType   string                  `json:"providerType,omitempty"`
	BaseURL        string                  `json:"baseUrl"`
	Endpoints      OrgProviderEndpoints    `json:"endpoints"`
	Capabilities   OrgProviderCapabilities `json:"capabilities"`
	Models         []OrgProviderModel      `json:"models"`
	Status         string                  `json:"status"`
	CreatedAt      time.Time               `json:"createdAt"`
	UpdatedAt      time.Time               `json:"updatedAt"`
}

// --- Provider Token ---

// OrgProviderTokenConfig is the browser-facing provider token config shape.
type OrgProviderTokenConfig struct {
	Role                string   `json:"role,omitempty"`
	BaseURL             string   `json:"baseUrl,omitempty"`
	Mode                string   `json:"mode,omitempty"`
	BackendName         string   `json:"backendName,omitempty"`
	BackendID           int      `json:"backendId,omitempty"`
	Active              *bool    `json:"active,omitempty"`
	Weight              float64  `json:"weight,omitempty"`
	WeightDiffThreshold float64  `json:"weightDiffThreshold,omitempty"`
	AdaptiveWeights     bool     `json:"adaptiveWeights,omitempty"`
	RequiresOAuthBeta   bool     `json:"requiresOAuthBeta,omitempty"`
	AllowedAPIKeys      []string `json:"allowedApiKeys,omitempty"`
	CustomPrompt        string   `json:"customPrompt,omitempty"`
	CustomPromptModels  []string `json:"customPromptModels,omitempty"`
}

// OrgProviderTokenView is the browser-facing organization provider token shape.
type OrgProviderTokenView struct {
	ID                     string                 `json:"id"`
	OrganizationID         string                 `json:"organizationId"`
	OrganizationProviderID string                 `json:"organizationProviderId"`
	Label                  string                 `json:"label"`
	TokenHint              string                 `json:"tokenHint"`
	Config                 OrgProviderTokenConfig `json:"config"`
	Status                 string                 `json:"status"`
	LastUsedAt             *time.Time             `json:"lastUsedAt"`
	LastErrorAt            *time.Time             `json:"lastErrorAt"`
	LastErrorCode          string                 `json:"lastErrorCode"`
	CreatedAt              time.Time              `json:"createdAt"`
	UpdatedAt              time.Time              `json:"updatedAt"`
}

// --- Provider Route ---

// OrgProviderRouteView is the browser-facing organization provider route shape.
type OrgProviderRouteView struct {
	ID             string             `json:"id"`
	OrganizationID string             `json:"organizationId"`
	Vendor         string             `json:"vendor"`
	DisplayName    string             `json:"displayName"`
	Models         []OrgProviderModel `json:"models"`
	SourceKind     string             `json:"sourceKind"`
	Status         string             `json:"status"`
	CreatedAt      time.Time          `json:"createdAt"`
	UpdatedAt      time.Time          `json:"updatedAt"`
}

// OrgProviderRouteGroupView is the browser-facing organization provider route group shape.
type OrgProviderRouteGroupView struct {
	ID              string    `json:"id"`
	OrganizationID  string    `json:"organizationId"`
	RouteID         string    `json:"routeId"`
	Models          []string  `json:"models"`
	ProviderRefs    []string  `json:"providerRefs"`
	Strategy        string    `json:"strategy"`
	Priority        int       `json:"priority"`
	ManagedBySystem bool      `json:"managedBySystem"`
	Status          string    `json:"status"`
	CreatedAt       time.Time `json:"createdAt"`
	UpdatedAt       time.Time `json:"updatedAt"`
}

// --- Workspace Grants ---

// OrgWorkspaceProviderGrantView is the browser-facing workspace provider grant shape.
type OrgWorkspaceProviderGrantView struct {
	WorkspaceID   string             `json:"workspaceId"`
	ProviderID    string             `json:"providerId"`
	ProviderName  string             `json:"providerName"`
	DriverKind    string             `json:"driverKind"`
	ProviderType  string             `json:"providerType,omitempty"`
	BaseURL       string             `json:"baseUrl"`
	Models        []OrgProviderModel `json:"models"`
	Status        string             `json:"status"`
	GrantedAt     time.Time          `json:"grantedAt"`
	LastUpdatedAt time.Time          `json:"updatedAt"`
}

// OrgWorkspaceRouteGrantView is the browser-facing workspace route grant shape.
type OrgWorkspaceRouteGrantView struct {
	WorkspaceID   string             `json:"workspaceId"`
	RouteID       string             `json:"routeId"`
	Vendor        string             `json:"vendor"`
	DisplayName   string             `json:"displayName"`
	Models        []OrgProviderModel `json:"models"`
	Status        string             `json:"status"`
	GrantedAt     time.Time          `json:"grantedAt"`
	LastUpdatedAt time.Time          `json:"updatedAt"`
}

// OrganizationHostedModelsResponse is the org-scoped hosted model inventory.
type OrganizationHostedModelsResponse struct {
	Object               string                              `json:"object"`
	OrganizationID       string                              `json:"organizationId"`
	EntitlementStatus    string                              `json:"entitlementStatus,omitempty"`
	BalanceStatus        string                              `json:"balanceStatus,omitempty"`
	AvailableCreditAtoms int64                               `json:"availableCreditAtoms,omitempty"`
	CreditUnit           string                              `json:"creditUnit,omitempty"`
	UpdatedAt            *time.Time                          `json:"updatedAt,omitempty"`
	Models               []OrganizationHostedModelView       `json:"models"`
	HostedAvailability   SelectableHostedAvailabilitySummary `json:"hostedAvailability"`
}

// OrganizationHostedModelView is one AgentTeam-hosted inventory row.
type OrganizationHostedModelView struct {
	HostedModelID                             string                           `json:"hostedModelId"`
	ModelReference                            string                           `json:"modelReference"`
	DisplayName                               string                           `json:"displayName"`
	Enabled                                   bool                             `json:"enabled"`
	Reasons                                   []string                         `json:"reasons,omitempty"`
	InventoryStatus                           string                           `json:"inventoryStatus"`
	EntitlementStatus                         string                           `json:"entitlementStatus"`
	AccessSource                              string                           `json:"accessSource,omitempty"`
	BalanceStatus                             string                           `json:"balanceStatus"`
	RuntimeStatus                             string                           `json:"runtimeStatus"`
	PricingFormulaVersion                     string                           `json:"pricingFormulaVersion,omitempty"`
	BillableDimensions                        []string                         `json:"billableDimensions,omitempty"`
	ContextTiers                              []HostedModelPricingTierResponse `json:"contextTiers,omitempty"`
	SupportedFamilies                         []string                         `json:"supportedFamilies,omitempty"`
	ExecutableWireAPIFamilies                 []string                         `json:"executableWireApiFamilies,omitempty"`
	MessagesFeatures                          []string                         `json:"messagesFeatures,omitempty"`
	ChatCompletionsFeatures                   []string                         `json:"chatCompletionsFeatures,omitempty"`
	ResponsesFeatures                         []string                         `json:"responsesFeatures,omitempty"`
	InputCreditAtomsPerMillionTokens          *int64                           `json:"inputCreditAtomsPerMillionTokens,omitempty"`
	CacheReadInputCreditAtomsPerMillionTokens *int64                           `json:"cacheReadInputCreditAtomsPerMillionTokens,omitempty"`
	OutputCreditAtomsPerMillionTokens         *int64                           `json:"outputCreditAtomsPerMillionTokens,omitempty"`
	UpdatedAt                                 time.Time                        `json:"updatedAt,omitempty"`
}

// OrganizationHostedModelSettingsView is the browser-facing hosted access policy.
type OrganizationHostedModelSettingsView struct {
	OrganizationID             string    `json:"organizationId"`
	PickerVisibilityPolicy     string    `json:"pickerVisibilityPolicy"`
	AutoAuthorizationEnabled   bool      `json:"autoAuthorizationEnabled"`
	AutoAuthorizationMode      string    `json:"autoAuthorizationMode"`
	AutoAuthorizationModelRefs []string  `json:"autoAuthorizationModelRefs"`
	UpdatedAt                  time.Time `json:"updatedAt"`
}

// OrganizationWorkspaceHostedModelAuthorizationView is the browser-facing workspace hosted access state.
type OrganizationWorkspaceHostedModelAuthorizationView struct {
	OrganizationID           string    `json:"organizationId"`
	WorkspaceID              string    `json:"workspaceId"`
	AuthorizationMode        string    `json:"authorizationMode"`
	SelectedModelRefs        []string  `json:"selectedModelRefs"`
	Status                   string    `json:"status"`
	Configured               bool      `json:"configured"`
	AuthorizedByUserID       string    `json:"authorizedByUserId"`
	AffectedHostedAgentCount int       `json:"affectedHostedAgentCount"`
	CreatedAt                time.Time `json:"createdAt"`
	UpdatedAt                time.Time `json:"updatedAt"`
}

// --- LLM Proxy Keys ---

// OrgLLMProxyKeyView is the browser-facing LLM proxy key shape.
type OrgLLMProxyKeyView struct {
	ID             string     `json:"id"`
	OrganizationID string     `json:"organizationId"`
	Label          string     `json:"label"`
	TokenHint      string     `json:"tokenHint"`
	Status         string     `json:"status"`
	LastUsedAt     *time.Time `json:"lastUsedAt"`
	LastErrorAt    *time.Time `json:"lastErrorAt"`
	LastErrorCode  string     `json:"lastErrorCode"`
	CreatedAt      time.Time  `json:"createdAt"`
	UpdatedAt      time.Time  `json:"updatedAt"`
}

// OrgLLMProxyKeyCreateResult is the result of creating an LLM proxy key.
type OrgLLMProxyKeyCreateResult struct {
	Key   OrgLLMProxyKeyView `json:"key"`
	Token string             `json:"token"`
}

// --- LLM Stats ---

// OrgLLMStatsSummaryView is the browser-facing LLM usage summary row.
type OrgLLMStatsSummaryView struct {
	SubjectType          string  `json:"subjectType"`
	SubjectID            string  `json:"subjectId"`
	SubjectName          string  `json:"subjectName"`
	Source               string  `json:"source"`
	Count1h              uint64  `json:"count1h"`
	Count6h              uint64  `json:"count6h"`
	Count1d              uint64  `json:"count1d"`
	Count3d              uint64  `json:"count3d"`
	Count1w              uint64  `json:"count1w"`
	InputTokens          uint64  `json:"inputTokens"`
	CachedInputTokens    uint64  `json:"cachedInputTokens"`
	OutputTokens         uint64  `json:"outputTokens"`
	TokenSpeed           float64 `json:"tokenSpeed"`
	CurrentDailySpentUSD float64 `json:"currentDailySpentUsd"`
	DailyQuotaUSD        float64 `json:"dailyQuotaUsd"`
}

// OrgLLMModelStatView is the browser-facing per-model stat row.
type OrgLLMModelStatView struct {
	Model             string  `json:"model"`
	ModelName         string  `json:"modelName"`
	ProviderID        string  `json:"providerId"`
	Provider          string  `json:"provider"`
	Count1h           uint64  `json:"count1h"`
	Count6h           uint64  `json:"count6h"`
	Count1d           uint64  `json:"count1d"`
	Count3d           uint64  `json:"count3d"`
	Count1w           uint64  `json:"count1w"`
	InputTokens       uint64  `json:"inputTokens"`
	CachedInputTokens uint64  `json:"cachedInputTokens"`
	OutputTokens      uint64  `json:"outputTokens"`
	TokenSpeed        float64 `json:"tokenSpeed"`
}

// OrgLLMStatsDetailView is the browser-facing per-subject stat detail row.
type OrgLLMStatsDetailView struct {
	SubjectType string                `json:"subjectType"`
	SubjectID   string                `json:"subjectId"`
	SubjectName string                `json:"subjectName"`
	Source      string                `json:"source"`
	Models      []OrgLLMModelStatView `json:"models"`
}

// OrgLLMTimeSeriesPoint is one data point in an LLM usage time series.
type OrgLLMTimeSeriesPoint struct {
	Timestamp int64  `json:"timestamp"`
	Count     uint64 `json:"count"`
	Input     uint64 `json:"input"`
	Cached    uint64 `json:"cached"`
	Output    uint64 `json:"output"`
}

// OrgLLMTimeSeriesView is the browser-facing LLM usage time series payload.
type OrgLLMTimeSeriesView struct {
	Interval int                     `json:"interval"`
	Data     []OrgLLMTimeSeriesPoint `json:"data"`
}

// OrgLLMErrorTypeStatsView is the browser-facing per-error-class stat row.
type OrgLLMErrorTypeStatsView struct {
	Type        string `json:"type"`
	Label       string `json:"label"`
	Color       string `json:"color"`
	Description string `json:"description"`
	Count1h     uint64 `json:"count1h"`
	Count6h     uint64 `json:"count6h"`
	Count12h    uint64 `json:"count12h"`
	Count24h    uint64 `json:"count24h"`
	Count1w     uint64 `json:"count1w"`
}

// OrgLLMErrorSummaryView is the browser-facing LLM error summary payload.
type OrgLLMErrorSummaryView struct {
	LastErrorTime   int64                      `json:"lastErrorTime"`
	Total1h         uint64                     `json:"total1h"`
	Total6h         uint64                     `json:"total6h"`
	Total12h        uint64                     `json:"total12h"`
	Total24h        uint64                     `json:"total24h"`
	Total1w         uint64                     `json:"total1w"`
	RequestCount1h  uint64                     `json:"requestCount1h"`
	RequestCount6h  uint64                     `json:"requestCount6h"`
	RequestCount12h uint64                     `json:"requestCount12h"`
	RequestCount24h uint64                     `json:"requestCount24h"`
	RequestCount1w  uint64                     `json:"requestCount1w"`
	ErrorTypes      []OrgLLMErrorTypeStatsView `json:"errorTypes"`
}

// OrgLLMErrorTimeSeriesPoint is one data point in an LLM error time series.
type OrgLLMErrorTimeSeriesPoint struct {
	Timestamp int64             `json:"timestamp"`
	Errors    map[string]uint64 `json:"errors"`
	Total     uint64            `json:"total"`
}

// OrgLLMErrorTimeSeriesView is the browser-facing LLM error time series payload.
type OrgLLMErrorTimeSeriesView struct {
	Interval int                          `json:"interval"`
	Data     []OrgLLMErrorTimeSeriesPoint `json:"data"`
}

// OrgLLMQuotaPolicyView is the browser-facing LLM quota policy row.
type OrgLLMQuotaPolicyView struct {
	SubjectType       string    `json:"subjectType"`
	SubjectID         string    `json:"subjectId"`
	SubjectName       string    `json:"subjectName"`
	Source            string    `json:"source"`
	Status            string    `json:"status"`
	DailyQuotaUSD     float64   `json:"dailyQuotaUsd"`
	CurrentSpentUSD   float64   `json:"currentSpentUsd"`
	RemainingUSD      float64   `json:"remainingUsd"`
	RequestCount      uint64    `json:"requestCount"`
	InputTokens       uint64    `json:"inputTokens"`
	CachedInputTokens uint64    `json:"cachedInputTokens"`
	OutputTokens      uint64    `json:"outputTokens"`
	UpdatedAt         time.Time `json:"updatedAt"`
}
