File size: 2,862 Bytes
ddebc3e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
"""Command / query objects for the account control plane."""

from typing import Any

from pydantic import BaseModel, Field

from .enums import AccountStatus


class AccountUpsert(BaseModel):
    """Create-or-replace command for a single account.

    Only ``token`` is required; all other fields use safe defaults.
    """

    token: str
    pool:  str = "basic"
    tags:  list[str] = Field(default_factory=list)
    ext:   dict[str, Any] = Field(default_factory=dict)


class AccountPatch(BaseModel):
    """Partial update — only supplied fields are written.

    Fields left as ``None`` are **not** modified in the backend.
    """

    token:            str
    pool:             str | None             = None  # update pool type when inferred
    status:           AccountStatus | None   = None
    tags:             list[str] | None       = None
    add_tags:         list[str] | None       = None
    remove_tags:      list[str] | None       = None
    # Per-mode quota patches (raw dicts matching QuotaWindow.to_dict()).
    quota_auto:       dict[str, Any] | None  = None
    quota_fast:       dict[str, Any] | None  = None
    quota_expert:     dict[str, Any] | None  = None
    quota_heavy:      dict[str, Any] | None  = None
    quota_grok_4_3:   dict[str, Any] | None  = None
    quota_console:    dict[str, Any] | None  = None
    # Usage counters — delta values (added to existing counts).
    usage_use_delta:  int | None             = None
    usage_fail_delta: int | None             = None
    usage_sync_delta: int | None             = None
    # Timestamp overrides (set absolute values).
    last_use_at:      int | None             = None
    last_fail_at:     int | None             = None
    last_fail_reason: str | None             = None
    last_sync_at:     int | None             = None
    last_clear_at:    int | None             = None
    state_reason:     str | None             = None
    ext_merge:        dict[str, Any] | None  = None
    clear_failures:   bool                   = False


class ListAccountsQuery(BaseModel):
    """Query parameters for paginated account listing."""

    page:            int            = Field(default=1, ge=1)
    page_size:       int            = Field(default=50, ge=1, le=2000)
    pool:            str | None     = None
    status:          AccountStatus | None = None
    tags:            list[str]      = Field(default_factory=list)
    include_deleted: bool           = False
    sort_by:         str            = "updated_at"   # field name
    sort_desc:       bool           = True


class BulkReplacePoolCommand(BaseModel):
    """Replace all accounts in a pool atomically."""

    pool:    str
    upserts: list[AccountUpsert] = Field(default_factory=list)


__all__ = [
    "AccountUpsert",
    "AccountPatch",
    "ListAccountsQuery",
    "BulkReplacePoolCommand",
]