// SPEC: PJ2026-010403 API契约 draft-2026-06-17-r0; PJ2026-010401 Web工作台 draft-2026-06-17-r0; PJ2026-01060505 Workbench Performance draft-2026-06-17-p0.
// Responsibility: Cloud Web API and Workbench state type contracts shared by stores and components.

export type Tone = "ok" | "pending" | "blocked" | "error" | "warn" | "dev-live" | "dry-run";
export type AuthState = "checking" | "login" | "authenticated";
export type ProviderProfile = string;
export type ChatRole = "user" | "agent" | "system";
export type ChatStatus = "pending" | "sent" | "running" | "completed" | "failed" | "blocked" | "timeout" | "canceled";
export type AccessUserRole = "admin" | "member" | "viewer" | string;
export type AccessUserStatus = "active" | "disabled" | "pending" | string;
export type AccessToolId = "code-agent" | "hwpod" | "provider-profiles" | "access-admin" | string;

export interface AuthUser {
  id?: string;
  username?: string;
  displayName?: string;
  name?: string;
  role?: AccessUserRole;
  status?: AccessUserStatus;
}

export type AuthCapabilityStatus = "available" | "forbidden" | "unlinked" | "unavailable" | string;

export interface AuthCapabilities {
  web?: AuthCapabilityStatus;
  workbench?: AuthCapabilityStatus;
  codeAgent?: AuthCapabilityStatus;
  billing?: AuthCapabilityStatus;
  apiKeys?: AuthCapabilityStatus;
  admin?: AuthCapabilityStatus;
  [key: string]: AuthCapabilityStatus | undefined;
}

export interface AuthSession {
  authenticated: boolean;
  mode: "server";
  authMethod?: string | null;
  identityAuthority?: string | null;
  sessionKind?: string | null;
  user?: AuthUser;
  actor?: AuthUser;
  capabilities?: AuthCapabilities;
  expiresAt?: string | null;
  valuesRedacted?: boolean;
}

export interface ApiResult<T> {
  ok: boolean;
  status: number;
  data: T | null;
  error: string | null;
  apiError?: ApiError | null;
  diagnostic?: ErrorDiagnostic | null;
}

export interface ErrorDiagnostic {
  contractVersion?: string | null;
  traceId?: string | null;
  requestId?: string | null;
  serviceId?: string | null;
  route?: string | null;
  layer?: string | null;
  category?: string | null;
  code?: string | number | null;
  httpStatus?: number | null;
  source?: "server" | "browser" | string | null;
  observedAt?: string | null;
  retryable?: boolean | null;
  valuesPrinted?: boolean;
  [key: string]: unknown;
}

export interface ApiError {
  message: string;
  userMessage?: string | null;
  code?: string | number | null;
  reason?: string | null;
  retryable?: boolean | null;
  layer?: string | null;
  category?: string | null;
  route?: string | null;
  traceId?: string | null;
  requestId?: string | null;
  source?: "server" | "browser" | string | null;
  diagnostic?: ErrorDiagnostic | null;
  valuesPrinted?: boolean;
  [key: string]: unknown;
}

export interface LiveProbePayload {
  status?: string;
  serviceId?: string;
  commitId?: string;
  revision?: string;
  runtime?: Record<string, unknown>;
  codeAgent?: CodeAgentAvailability;
  availability?: CodeAgentAvailability;
  [key: string]: unknown;
}

export interface LiveBuildsPayload {
  status?: string;
  observedAt?: string;
  builds?: Array<Record<string, unknown>>;
  [key: string]: unknown;
}

export interface LiveSurface {
  healthLive: ApiResult<LiveProbePayload>;
  health: ApiResult<LiveProbePayload>;
  restIndex: ApiResult<LiveProbePayload>;
  hwpodSpecs: ApiResult<HwpodSpecsResponse>;
  hwpodNodeOps: ApiResult<HwpodNodeOpsResponse>;
  liveBuilds: ApiResult<LiveBuildsPayload>;
  loadedAt: string;
}

export interface CodeAgentAvailability {
  status?: string;
  ready?: boolean;
  provider?: string;
  mode?: string;
  backend?: string;
  capabilityLevel?: string;
  sessionMode?: string;
  blockers?: Array<{ code?: string; message?: string }>;
  [key: string]: unknown;
}

export interface ProjectionBlocker {
  code?: string;
  message?: string | null;
  summary?: string | null;
  userMessage?: string | null;
  layer?: string | null;
  category?: string | null;
  retryable?: boolean | null;
  route?: string | null;
  traceId?: string | null;
  requestId?: string | null;
  source?: "server" | "browser" | string | null;
  httpStatus?: number | null;
  diagnostic?: ErrorDiagnostic | null;
  runId?: string | null;
  commandId?: string | null;
  timeoutMs?: number | null;
  [key: string]: unknown;
}

export interface ProjectionDiagnostic {
  projectionStatus?: string | null;
  projectionHealth?: "caught-up" | "degraded" | "stalled" | "unavailable" | "unknown" | string | null;
  lastProjectedSeq?: number | null;
  sourceRunId?: string | null;
  sourceCommandId?: string | null;
  staleMs?: number | null;
  blocker?: ProjectionBlocker | null;
  diagnostic?: ErrorDiagnostic | null;
  apiError?: ApiError | null;
  updatedAt?: string | null;
  valuesRedacted?: boolean;
  [key: string]: unknown;
}

export interface WorkbenchTurnTimingProjection {
  startedAt?: string | null;
  lastEventAt?: string | null;
  finishedAt?: string | null;
  durationMs?: number | null;
  observedAt?: string | null;
  lastEventAgeMs?: number | null;
  valuesRedacted?: boolean;
  [key: string]: unknown;
}

export interface WorkbenchSessionRecord {
  sessionId: string;
  threadId?: string | null;
  status?: string | null;
  updatedAt?: string | null;
  lastUserMessageAt?: string | null;
  startedAt?: string | null;
  lastTraceId?: string | null;
  messageCount?: number;
  firstUserMessagePreview?: string | null;
  title?: string | null;
  name?: string | null;
  snapshot?: Record<string, unknown> | null;
  userPreview?: string | null;
  messages?: ChatMessage[];
  projection?: ProjectionDiagnostic | null;
  timing?: WorkbenchTurnTimingProjection | null;
  lastEventAt?: string | null;
  finishedAt?: string | null;
  durationMs?: number | null;
  projectionStatus?: string | null;
  projectionHealth?: string | null;
  staleMs?: number | null;
  blocker?: ProjectionBlocker | null;
  [key: string]: unknown;
}

export interface TraceEvent {
  ts?: string;
  label?: string;
  kind?: string;
  type?: string;
  status?: string;
  message?: string;
  text?: string;
  outputSummary?: string;
  itemId?: string;
  toolName?: string;
  command?: string;
  exitCode?: number;
  stdoutSummary?: string;
  stderrSummary?: string;
  elapsedMs?: number;
  final?: boolean;
  terminal?: boolean;
  replyAuthority?: boolean;
  [key: string]: unknown;
}

export interface RunnerTrace {
  traceId?: string;
  status?: string;
  sessionId?: string;
  threadId?: string;
  runnerKind?: string;
  sessionMode?: string;
  events?: TraceEvent[];
  eventCount?: number;
  eventsCompacted?: boolean;
  fullTraceLoaded?: boolean;
  hasMore?: boolean;
  truncated?: boolean;
  nextProjectedSeq?: number | null;
  range?: { afterProjectedSeq?: number; fromProjectedSeq?: number | null; toProjectedSeq?: number | null; limit?: number; returned?: number; total?: number; [key: string]: unknown };
  lastEventLabel?: string;
  waitingFor?: string;
  timing?: WorkbenchTurnTimingProjection | null;
  startedAt?: string | null;
  lastEventAt?: string | null;
  finishedAt?: string | null;
  durationMs?: number | null;
  projection?: ProjectionDiagnostic | null;
  projectionStatus?: string | null;
  projectionHealth?: string | null;
  staleMs?: number | null;
  blocker?: ProjectionBlocker | null;
  [key: string]: unknown;
}

export interface ChatMessage {
  id: string;
  role: ChatRole;
  title: string;
  text: string;
  status: ChatStatus;
  createdAt: string;
  updatedAt?: string;
  traceId?: string | null;
  turnId?: string | null;
  messageId?: string | null;
  sessionId?: string | null;
  threadId?: string | null;
  retryInput?: string | null;
  runnerTrace?: RunnerTrace | null;
  traceEvents?: TraceEvent[];
  timing?: WorkbenchTurnTimingProjection | null;
  startedAt?: string | null;
  lastEventAt?: string | null;
  finishedAt?: string | null;
  durationMs?: number | null;
  error?: { code?: string | number | null; message?: string; userMessage?: string | null; category?: string | null; layer?: string | null; providerStatus?: number; retryable?: boolean | null; route?: string | null; traceId?: string | null; requestId?: string | null; source?: "server" | "browser" | string | null; diagnostic?: ErrorDiagnostic | null; [key: string]: unknown } | null;
  traceAutoLifecycle?: "running" | "terminal" | null;
  projection?: ProjectionDiagnostic | null;
  projectionStatus?: string | null;
  projectionHealth?: string | null;
  staleMs?: number | null;
  blocker?: ProjectionBlocker | null;
  [key: string]: unknown;
}

export interface AgentRunProvenance {
  adapter?: string;
  runId?: string;
  commandId?: string;
  attemptId?: string;
  runnerId?: string;
  jobName?: string;
  namespace?: string;
  backendProfile?: string;
  status?: string;
  commandState?: string;
  terminalStatus?: string;
  valuesPrinted?: boolean;
  [key: string]: unknown;
}

export interface AgentChatResponse {
  status?: string;
  reply?: string | AgentChatReply;
  text?: string;
  summary?: string;
  traceId?: string;
  turnId?: string | null;
  userMessageId?: string | null;
  assistantMessageId?: string | null;
  sessionId?: string;
  threadId?: string;
  sessionStatus?: string;
  availability?: CodeAgentAvailability;
  runnerTrace?: RunnerTrace;
  traceEvents?: TraceEvent[];
  assistantText?: string;
  agentRun?: AgentRunProvenance;
  resultUrl?: string;
  traceUrl?: string;
  turnUrl?: string;
  accepted?: boolean;
  shortConnection?: boolean;
  running?: boolean;
  terminal?: boolean;
  timing?: WorkbenchTurnTimingProjection | null;
  startedAt?: string | null;
  lastEventAt?: string | null;
  finishedAt?: string | null;
  durationMs?: number | null;
  updatedAt?: string;
  lastEventLabel?: string;
  waitingFor?: string;
  error?: string | { code?: string; message?: string; providerStatus?: number; [key: string]: unknown };
  projection?: ProjectionDiagnostic | null;
  projectionStatus?: string | null;
  projectionHealth?: string | null;
  staleMs?: number | null;
  blocker?: ProjectionBlocker | null;
  [key: string]: unknown;
}

export interface AgentChatReply {
  messageId?: string;
  role?: "assistant" | "user" | "system";
  content?: string;
  createdAt?: string;
  [key: string]: unknown;
}

export type AgentChatResultResponse = AgentChatResponse & {
  events?: TraceEvent[];
  eventCount?: number;
  fullTraceLoaded?: boolean;
  hasMore?: boolean;
  truncated?: boolean;
  nextProjectedSeq?: number | null;
  range?: { afterProjectedSeq?: number; fromProjectedSeq?: number | null; toProjectedSeq?: number | null; limit?: number; returned?: number; total?: number; [key: string]: unknown };
  traceStatus?: string;
  retention?: unknown;
  terminalEvidence?: unknown;
  finalResponse?: unknown;
  traceSummary?: unknown;
  lastEventLabel?: string;
};

export interface HwpodSpecsResponse { specs?: Array<Record<string, unknown>>; [key: string]: unknown }
export interface HwpodNodeOpsResponse { ok?: boolean; status?: string; events?: TraceEvent[]; groups?: Array<Record<string, unknown>>; [key: string]: unknown }
export interface ProviderProfilesResponse { ok?: boolean; status?: string; profiles?: Array<Record<string, unknown>>; [key: string]: unknown }
export interface ProviderProfileValidation { validationId?: string; status?: string; [key: string]: unknown }
export interface GateDiagnosticRow extends Record<string, unknown> {
  category?: string;
  check?: string;
  status?: string;
  statusKey?: string;
  owner?: string;
  detail?: string;
  evidence?: string | string[];
  updatedAt?: string;
  next?: string;
}

export interface GateDiagnosticsResponse {
  status?: string;
  route?: string;
  contractVersion?: string;
  sourceKind?: string;
  liveBackend?: boolean;
  observedAt?: string;
  rowCount?: number;
  rows?: GateDiagnosticRow[];
  safety?: Record<string, unknown>;
  [key: string]: unknown;
}

export interface WebPerformanceRow extends Record<string, unknown> {
  kind?: string;
  metric?: string;
  route?: string;
  method?: string;
  statusClass?: string;
  outcome?: string;
  count?: number;
  average?: number;
  p50?: number;
  p75?: number;
  p95?: number;
  unit?: "seconds" | "score" | string;
  sourceFamily?: string;
  windowFrom?: string | null;
  windowTo?: string;
  generatedAt?: string;
  sampleCount?: number;
  freshness?: "fresh" | "low-sample" | "empty" | string;
  aggregationKind?: "exact" | "histogram" | string;
  approximation?: "exact" | "bucketed" | string;
  bucketBoundaries?: number[];
  tone?: "ok" | "warn" | "blocked" | "pending" | string;
  problem?: string;
  lowSample?: boolean;
  sampleState?: "ok" | "low-sample" | "empty" | string;
  backend?: string;
  transport?: string;
  targetState?: string;
  cache?: string;
  source?: string;
  entry?: string;
  authState?: string;
  eventType?: string;
  phase?: string;
  backendEvidence?: {
    status?: "matched" | "missing" | "unavailable" | string;
    statusLabel?: string;
    diagnostic?: string;
    diagnosticLabel?: string;
    detail?: string;
    route?: string;
    method?: string;
    count?: number;
    p50?: number;
    p75?: number;
    p95?: number;
    responseBytesP95?: number | null;
    lastObservedAt?: string | null;
    phases?: Array<{ phase?: string; outcome?: string; count?: number; p95?: number }>;
  };
}

export type WebPerformanceWindow = "5m" | "15m" | "1h" | "6h" | "24h" | "all";

export interface WebPerformanceSampleWindow extends Record<string, unknown> {
  id?: WebPerformanceWindow | string;
  label?: string;
  seconds?: number | null;
  windowFrom?: string | null;
  windowTo?: string;
  generatedAt?: string;
  aggregationKind?: "exact" | "histogram" | string;
  approximation?: "exact" | "bucketed" | string;
}

export interface WebPerformanceDashboardPoint extends Record<string, unknown> {
  label?: string;
  detail?: string;
  value?: number;
  p50?: number;
  p75?: number;
  p95?: number;
  count?: number;
  tone?: string;
  sampleState?: string;
}

export interface WebPerformanceDashboardTrend extends Record<string, unknown> {
  id?: string;
  title?: string;
  subtitle?: string;
  unit?: string;
  points?: WebPerformanceDashboardPoint[];
}

export interface WebPerformanceDashboardDistributionBucket extends Record<string, unknown> {
  label?: string;
  count?: number;
  tone?: string;
}

export interface WebPerformanceDashboardDistribution extends Record<string, unknown> {
  id?: string;
  title?: string;
  subtitle?: string;
  unit?: string;
  buckets?: WebPerformanceDashboardDistributionBucket[];
}

export interface WebPerformanceDashboardTopRow extends Record<string, unknown> {
  label?: string;
  detail?: string;
  value?: number;
  unit?: string;
  count?: number;
  tone?: string;
}

export interface WebPerformanceDashboardTopN extends Record<string, unknown> {
  id?: string;
  title?: string;
  subtitle?: string;
  unit?: string;
  rows?: WebPerformanceDashboardTopRow[];
}

export interface WebPerformanceDashboardCard extends Record<string, unknown> {
  id?: string;
  label?: string;
  value?: string | number;
  unit?: string;
  tone?: string;
  detail?: string;
}

export interface WebPerformanceCollectionHealthDiagnostic extends Record<string, unknown> {
  code?: string;
  label?: string;
  tone?: string;
  detail?: string;
}

export interface WebPerformanceCollectionHealth extends Record<string, unknown> {
  schemaVersion?: string;
  status?: string;
  statusLabel?: string;
  reason?: string;
  reasonLabel?: string;
  sampleCount?: number;
  retainedSampleCount?: number;
  sampleSeries?: number;
  lowSampleThreshold?: number;
  firstSampleAt?: string | null;
  lastSampleAt?: string | null;
  lastRetainedSampleAt?: string | null;
  secondsSinceLastSample?: number | null;
  windowCoverageSeconds?: number | null;
  sourceFamilyCounts?: Array<{ sourceFamily?: string; rowCount?: number; sampleCount?: number; [key: string]: unknown }>;
  unknownAttribution?: { workbenchRows?: number; attributableRows?: number; rowsWithUnknown?: number; samplesWithUnknown?: number; backendUnknownRows?: number; transportUnknownRows?: number; [key: string]: unknown };
  diagnostics?: WebPerformanceCollectionHealthDiagnostic[];
}

export interface WebPerformanceDashboard extends Record<string, unknown> {
  schemaVersion?: string;
  generatedAt?: string;
  sampleWindow?: WebPerformanceSampleWindow & { buckets?: Array<Record<string, unknown>>; [key: string]: unknown };
  freshness?: { observedAt?: string; source?: string; namespace?: string; gitopsTarget?: string; status?: string; statusLabel?: string; lowSampleThreshold?: number; generatedAt?: string; windowFrom?: string | null; windowTo?: string; sampleCount?: number; sourceFamily?: string; [key: string]: unknown };
  collectionHealth?: WebPerformanceCollectionHealth;
  cards?: WebPerformanceDashboardCard[];
  trends?: WebPerformanceDashboardTrend[];
  distributions?: WebPerformanceDashboardDistribution[];
  topN?: WebPerformanceDashboardTopN[];
}

export interface WebPerformanceSummaryResponse {
  status?: string;
  source?: string;
  observedAt?: string;
  namespace?: string;
  gitopsTarget?: string;
  sampleWindow?: WebPerformanceSampleWindow;
  summary?: { sampleCount?: number; sampleSeries?: number; durationSeries?: number; clsSeries?: number; routeCount?: number; problemCount?: number; status?: string; lowSampleThreshold?: number; window?: WebPerformanceWindow | string; windowLabel?: string; windowSeconds?: number | null; windowFrom?: string | null; windowTo?: string; generatedAt?: string; aggregationKind?: "exact" | "histogram" | string; approximation?: "exact" | "bucketed" | string; [key: string]: unknown };
  backendEvidence?: { schemaVersion?: string; source?: string; observedAt?: string | null; sampleCount?: number; retainedSampleCount?: number; routeCount?: number; rows?: Array<Record<string, unknown>>; available?: boolean; valuesRedacted?: boolean; [key: string]: unknown };
  collectionHealth?: WebPerformanceCollectionHealth;
  dashboard?: WebPerformanceDashboard;
  apiRoutes?: WebPerformanceRow[];
  webVitals?: WebPerformanceRow[];
  longTasks?: WebPerformanceRow[];
  problems?: WebPerformanceRow[];
  workbenchJourneys?: WebPerformanceRow[];
  workbenchEventPhases?: WebPerformanceRow[];
  workbenchBackendEvents?: WebPerformanceRow[];
  workbenchCacheRows?: WebPerformanceRow[];
  workbenchRows?: WebPerformanceRow[];
  rows?: WebPerformanceRow[];
  [key: string]: unknown;
}

export interface SkillRecord extends Record<string, unknown> {
  id: string;
  source?: "preinstalled" | "uploaded" | string;
  name?: string;
  description?: string;
  version?: string | null;
  commitId?: string | null;
  rootDir?: string;
  manifestPath?: string | null;
  createdAt?: string | null;
  updatedAt?: string | null;
  fileCount?: number;
  sizeBytes?: number;
}

export interface SkillTreeEntry extends Record<string, unknown> { path: string; type?: "directory" | "file" | string; sizeBytes?: number | null }
export interface SkillFilePayload { path?: string; sizeBytes?: number; contentType?: string; content?: string }
export interface SkillsResponse { count?: number; skills?: SkillRecord[]; roots?: Record<string, string>; agentRunAssembly?: Record<string, unknown>; [key: string]: unknown }
export interface SkillUploadResponse { accepted?: boolean; skill?: SkillRecord; [key: string]: unknown }
export interface SkillTreeResponse { skill?: SkillRecord; tree?: SkillTreeEntry[]; count?: number; [key: string]: unknown }
export interface SkillFileResponse { skill?: SkillRecord; file?: SkillFilePayload; content?: string; [key: string]: unknown }

export interface AdminAccessSummaryResponse { summary?: Record<string, unknown>; [key: string]: unknown }
export interface AdminAccessUsersResponse { users?: AuthUser[]; [key: string]: unknown }
export interface AdminAccessMatrixResponse { user?: AuthUser; tools?: Array<Record<string, unknown>>; [key: string]: unknown }
export interface AdminAccessMutationResponse { ok?: boolean; user?: AuthUser; [key: string]: unknown }
export interface ApiKeyRecord { id: string; name?: string; prefix?: string; createdAt?: string; lastUsedAt?: string | null; revokedAt?: string | null; displaySecret?: string | null }
export interface UsageServiceSummary { serviceId: string; resourceType?: string; credits?: number; quantity?: number; recordCount?: number; lastUsedAt?: string }
export interface UsageLedgerRow { id: string; userId?: string; email?: string; username?: string; kind?: string; reason?: string; deltaCredits?: number; balanceBefore?: number; balanceAfter?: number; source?: string; status?: string; idempotencyKey?: string; operatorUserId?: string; operatorUsername?: string; metadata?: Record<string, unknown>; createdAt?: string }
export interface AdminUsageRow { id: string; reservationId?: string; userId?: string; email?: string; username?: string; apiKeyId?: string; serviceId?: string; resourceType?: string; unit?: string; quantity?: number; credits?: number; status?: string; idempotencyKey?: string; metadata?: Record<string, unknown>; createdAt?: string }
export interface UsageReservationRow { reservationId: string; serviceId?: string; resourceType?: string; estimatedCredits?: number; estimatedTokens?: number; status?: string; expiresAt?: string; createdAt?: string }
export interface BillingPlanSummary { id?: string; displayName?: string; status?: string; description?: string; metadata?: Record<string, unknown> }
export interface ResourceEntitlementSummary {
  id?: string;
  planId?: string;
  resourceType?: string;
  enabled?: boolean;
  monthlyQuotaCredits?: number;
  monthlyQuotaUnlimited?: boolean;
  monthlyUsageCredits?: number;
  monthlyRemainingCredits?: number;
  maxConcurrentReservations?: number;
  concurrencyUnlimited?: boolean;
  activeReservations?: number;
  rpmLimit?: number;
  rpmUnlimited?: boolean;
  rpmUsed?: number;
  limitSemantics?: string;
  metadata?: Record<string, unknown>;
}
export interface BillingPlanDetail { plan?: BillingPlanSummary; entitlements?: ResourceEntitlementSummary[] }
export interface UsageSummary {
  status?: string;
  contractVersion?: string;
  rows?: Array<Record<string, unknown>>;
  credits?: { balance?: number; reserved?: number; available?: number };
  planId?: string;
  plan?: BillingPlanSummary;
  entitlements?: ResourceEntitlementSummary[];
  usage?: { totalCredits?: number; totalQuantity?: number; recordCount?: number; byService?: UsageServiceSummary[] };
  ledger?: { count?: number; limit?: number; rows?: UsageLedgerRow[] };
  reservations?: { activeCount?: number; active?: UsageReservationRow[] };
  state?: { stateless?: boolean; stateAuthority?: string; database?: Record<string, unknown>; redis?: Record<string, unknown> };
  proxy?: Record<string, unknown>;
  valuesRedacted?: boolean;
  [key: string]: unknown;
}

export interface AdminBillingUserSummary {
  user?: AuthUser & { email?: string; emailVerified?: boolean; createdAt?: string };
  planId?: string;
  plan?: BillingPlanSummary;
  entitlements?: ResourceEntitlementSummary[];
  credits?: { balance?: number; reserved?: number; available?: number };
  usage?: { totalCredits?: number; totalQuantity?: number; recordCount?: number; lastUsedAt?: string | null };
  apiKeys?: { activeCount?: number; totalCount?: number; lastUsedAt?: string | null };
  reservations?: { activeCount?: number; active?: UsageReservationRow[] };
}

export interface AdminBillingSummary {
  status?: string;
  contractVersion?: string;
  count?: number;
  limit?: number;
  totals?: Record<string, number>;
  users?: AdminBillingUserSummary[];
  state?: { stateless?: boolean; stateAuthority?: string; database?: Record<string, unknown>; redis?: Record<string, unknown> };
  proxy?: Record<string, unknown>;
  valuesRedacted?: boolean;
  [key: string]: unknown;
}

export interface AdminBillingUsersResponse {
  status?: string;
  contractVersion?: string;
  count?: number;
  total?: number;
  users?: AdminBillingUserSummary[];
  pagination?: { page?: number; pageSize?: number; total?: number; totalPages?: number };
  state?: { stateless?: boolean; stateAuthority?: string; database?: Record<string, unknown>; redis?: Record<string, unknown> };
  proxy?: Record<string, unknown>;
  valuesRedacted?: boolean;
  [key: string]: unknown;
}

export interface AdminBillingPlansResponse {
  status?: string;
  contractVersion?: string;
  count?: number;
  plans?: BillingPlanDetail[];
  proxy?: Record<string, unknown>;
  valuesRedacted?: boolean;
  [key: string]: unknown;
}

export interface AdminBillingUserDetail {
  summary?: AdminBillingUserSummary;
  ledger?: { count?: number; rows?: UsageLedgerRow[] };
  apiKeys?: { count?: number; keys?: ApiKeyRecord[] };
  usageBy?: UsageServiceSummary[];
  reservations?: { count?: number; rows?: UsageReservationRow[]; active?: UsageReservationRow[] };
  [key: string]: unknown;
}

export interface AdminBillingUserDetailResponse {
  contractVersion?: string;
  detail?: AdminBillingUserDetail;
  actor?: AuthUser;
  proxy?: Record<string, unknown>;
  valuesRedacted?: boolean;
  [key: string]: unknown;
}

export interface AdminAuditResponse<T> {
  contractVersion?: string;
  rows?: T[];
  count?: number;
  total?: number;
  pagination?: { page?: number; pageSize?: number; total?: number; totalPages?: number };
  filters?: Record<string, unknown>;
  proxy?: Record<string, unknown>;
  valuesRedacted?: boolean;
  [key: string]: unknown;
}

export interface RedeemResult {
  redeemed?: boolean;
  idempotent?: boolean;
  redemptionId?: string;
  codeId?: string;
  codePrefix?: string;
  userId?: string;
  ledgerId?: string;
  creditAmount?: number;
  balanceBefore?: number;
  balanceAfter?: number;
  reason?: string;
  source?: string;
  status?: string;
  idempotencyKey?: string;
}

export interface RedeemResponse {
  contractVersion?: string;
  result?: RedeemResult;
  proxy?: Record<string, unknown>;
  valuesRedacted?: boolean;
  [key: string]: unknown;
}

export interface RedeemCodeSummary {
  id?: string;
  codePrefix?: string;
  displayName?: string;
  status?: string;
  creditAmount?: number;
  reason?: string;
  maxRedemptions?: number;
  perUserLimit?: number;
  redeemedCount?: number;
  remainingCount?: number;
  expiresAt?: string | null;
  createdByUserId?: string;
  createdByUsername?: string;
  metadata?: Record<string, unknown>;
  createdAt?: string;
  updatedAt?: string;
  disabledAt?: string | null;
}

export interface RedeemRedemptionSummary {
  id?: string;
  codeId?: string;
  codePrefix?: string;
  userId?: string;
  ledgerId?: string;
  creditAmount?: number;
  status?: string;
  idempotencyKey?: string;
  metadata?: Record<string, unknown>;
  createdAt?: string;
}

export interface AdminRedeemCodesResponse {
  contractVersion?: string;
  codes?: RedeemCodeSummary[];
  code?: RedeemCodeSummary;
  redeemCode?: string;
  created?: boolean;
  updated?: boolean;
  count?: number;
  proxy?: Record<string, unknown>;
  valuesRedacted?: boolean;
  [key: string]: unknown;
}

export interface AdminRedeemRedemptionsResponse {
  contractVersion?: string;
  redemptions?: RedeemRedemptionSummary[];
  count?: number;
  proxy?: Record<string, unknown>;
  valuesRedacted?: boolean;
  [key: string]: unknown;
}

export interface SubscriptionSummaryResponse {
  contractVersion?: string;
  planId?: string;
  plan?: BillingPlanSummary;
  entitlements?: ResourceEntitlementSummary[];
  subscriptions?: Array<Record<string, unknown>>;
  payment?: Record<string, unknown>;
  proxy?: Record<string, unknown>;
  valuesRedacted?: boolean;
  [key: string]: unknown;
}

export interface PaymentSummaryResponse {
  contractVersion?: string;
  provider?: Record<string, unknown>;
  orders?: Array<Record<string, unknown>>;
  count?: number;
  proxy?: Record<string, unknown>;
  valuesRedacted?: boolean;
  [key: string]: unknown;
}

export interface AdminBillingMutationResponse {
  ok?: boolean;
  userId?: string;
  status?: AccessUserStatus;
  user?: AuthUser;
  detail?: AdminBillingUserDetail;
  balance?: number;
  created?: boolean;
  updated?: boolean;
  actor?: AuthUser;
  proxy?: Record<string, unknown>;
  valuesRedacted?: boolean;
  [key: string]: unknown;
}

export interface Toast {
  id: string;
  type: "success" | "error" | "info" | "warning";
  message: string;
  duration?: number;
}
