
    =[j                    H
   U d Z ddlmZ ddlmZmZ ddlmZ ddlmZm	Z	m
Z
mZmZmZ ddlmZmZmZmZmZmZmZmZmZmZ ddlmZ d	Zed
hZded<   d ZddZee ee           eee d           eddd          f         Z!eee          ed            ed e d           eddgdd          f         Z"d Z#ddZ$ee ee#           ee$e d           eddd          f         Z% G d d e          Z& G d! d"e          Z' G d# d$e          Z( G d% d&e          Z) G d' d(e          Z* G d) d*e          Z+ G d+ d,e          Z, G d- d.e          Z- G d/ d0e          Z. G d1 d2e*          Z/ G d3 d4e          Z0 G d5 d6e*          Z1 G d7 d8e          Z2 G d9 d:e          Z3 G d; d<e3          Z4 G d= d>e3          Z5 G d? d@e3          Z6 G dA dBe3          Z7 G dC dDe3          Z8 G dE dFe3          Z9 G dG dHe3          Z: G dI dJe          Z; G dK dLe3          Z< G dM dNe3          Z= G dO dPe3          Z> G dQ dRe3          Z? G dS dTe3          Z@ G dU dVe3          ZA G dW dXe3          ZB G dY dZe3          ZC G d[ d\e3          ZD eEh d]          ZFd^ed_<   eee4e5e6e7e8e9e:e<e=e>e?e@eAeBeCf          ed`a          f         ZGe4e5e6e7e8e9e:e<e=e>e?e@eAeBeCdbZHdcedd<    G de dfeeeGeDf                            ZI eeI          ZJ G dg dheKeLeIf                   ZMdi ZN G dj dke          ZO G dl dme          ZP G dn doeM          ZQ G dp dqe          ZR G dr dse          ZS G dt due          ZT G dv dwe          ZU G dx dyeLe          ZV G dz d{e          ZW G d| d}eW          ZX G d~ deW          ZY G d deW          ZZ G d deW          Z[ G d deW          Z\eeeXeYeZe[e\f          ed`a          f         Z] G d de          Z^ G d de          Z_ G d de          Z` G d de          Za G d de          Zb G d de          Zc G d de          Zd G d de          Ze G d de          Zf G d de          Zg G d de          Zh G d de          Zi G d de          Zj G d de          Zk G d de          Zl G d de          Zm G d de          Zn G d de          Zo G d de          ZpdS )u   
CloudKit “wire” models for /records/query requests & responses.
- Response models (records) + refined request models (query payloads).
    )annotations)datetimetimezone)Enum)	AnnotatedDictListLiteralOptionalUnion)
Base64BytesBeforeValidatorField	JsonValuePlainSerializer	RootModelTypeAdapterWithJsonSchemafield_validatormodel_validator   )CKModell XY$b l 8b zset[int]SENTINEL_ZERO_MSc                   t          | t          t          f          rt          |           }n~t          | t                    rZ|                                 }|                    d          rd S 	 t          |          }n-# t          t          t          f$ r Y d S w xY wt          d          |t          v s|t          k    rd S 	 t          j        |dz  t          j                  S # t          t          t          f$ r Y d S w xY w)Nz
0001-01-01z:Expected milliseconds since epoch as int or numeric string     @@tz)
isinstanceintfloatstrstrip
startswith	TypeError
ValueErrorOverflowErrorr   CANONICAL_MIN_MSr   fromtimestampr   utcOSError)vivsvs      g/home/thesage/.hermes/hermes-agent/venv/lib/python3.11/site-packages/pyicloud/common/cloudkit/models.py_from_millis_or_noner/   )   s   !c5\"" WVV	As		 
WWWYY==&& 	4	RBB:}5 	 	 	44	 UVVV	'7!7!7t%b6khlCCCC/    tt	s$   .A> >BB"C% %D ?D dtr   returnr   c                    | j          |                     t          j                  } t	          |                                 dz            S )Ntzinfoi  r4   replacer   r)   r   	timestampr0   s    r.   
_to_millisr9   D   s:    	yZZx|Z,,r||~~$%%%    json)return_type	when_usedintegerzmilliseconds since Unix epoch)typedescriptionc                (    | d nt          |           S N)r/   r+   s    r.   <lambda>rD   U   s    aidd5I!5L5L r:   c                (    | d nt          |           S rB   )r9   rC   s    r.   rD   rD   W   s    !)$$A r:   nullz.milliseconds since Unix epoch or null sentinelc                   t          | t          t          f          rt          |           }net          | t                    rA	 t          |                                           }n-# t
          t          t          f$ r Y d S w xY wt          d          	 t          |          dk     r t          j
        |t          j                  S t          j
        |dz  t          j                  S # t          t          t          f$ r Y d S w xY w)Nz7Expected seconds or milliseconds since epoch as int/strl    h] r   r   )r   r   r    r!   r"   r$   r%   r&   absr   r(   r   r)   r*   )r+   r,   s     r.   _from_secs_or_millisrI   f   s    !c5\"" TVV	As		 T	QWWYYBB:}5 	 	 	44	 RSSSr77_$$)">>>>%b6khlCCCC/   tts*   !A% %B ?B 2C) "C) )DDc                    | j          |                     t          j                  } t	          |                                           S )Nr3   r5   r8   s    r.   _to_secsrK   z   s5    	yZZx|Z,,r||~~r:   zseconds since Unix epochc                  :    e Zd ZU dZded<   dZded<   dZded<   dS )CKZoneIDz=Identifies a CloudKit zone by name, owner, and optional type.r!   zoneNameNOptional[str]ownerRecordNamezoneType)__name__
__module____qualname____doc____annotations__rP   rQ    r:   r.   rM   rM      sC         GGMMM%)O))))"H""""""r:   rM   c                  :    e Zd ZU dZded<   dZded<   dZded<   dS )CKAuditInfozK
    Appears as `created` / `modified` at the record level (response).
    MillisDateTimer7   NrO   userRecordNamedeviceID)rR   rS   rT   rU   rV   r[   r\   rW   r:   r.   rY   rY      sL           $(N(((("H""""""r:   rY   c                      e Zd ZU dZded<   dS )CKParentz1References a parent record in a record hierarchy.r!   
recordNameNrR   rS   rT   rU   rV   rW   r:   r.   r^   r^      s         ;;OOOOOr:   r^   c                  Z    e Zd ZU dZdZded<   dZded<   dZded<   dZded<   dZ	ded<   dS )	CKStableUrlz7Secure URL and access credentials for sharing a record.NrO   
routingKeyshortTokenHashprotectedFullTokenencryptedPublicSharingKeydisplayedHostname)
rR   rS   rT   rU   rc   rV   rd   re   rf   rg   rW   r:   r.   rb   rb      sp         AA $J$$$$$(N(((((,,,,,/33333'+++++++r:   rb   c                  0    e Zd ZU dZdZded<   dZded<   dS )CKChainProtectionInfoz0End-to-end encryption chain protection metadata.NOptional[Base64Bytes]bytesrO   pcsChangeTag)rR   rS   rT   rU   rk   rV   rl   rW   r:   r.   ri   ri      s:         ::#'E''''"&L&&&&&&r:   ri   c                  0    e Zd ZU dZdZded<   dZded<   dS )CKSharea)  
    Minimal share reference as seen embedded under a record's top-level `share` key.
    Observed nested payloads only surfaced `recordName` and `zoneID` here.
    Keep this coarse for now; we can expand with shortGUID/shortTokenHash, etc.,
    if they appear nested here in future payloads.
    NrO   r_   Optional[CKZoneID]zoneID)rR   rS   rT   rU   r_   rV   rp   rW   r:   r.   rn   rn      s@           !%J$$$$!%F%%%%%%r:   rn   c                  0    e Zd ZU dZdZded<   dZded<   dS )CKNameComponentsz.User's name split into given and family names.NrO   	givenName
familyName)rR   rS   rT   rU   rs   rV   rt   rW   r:   r.   rr   rr      s:         88#I#### $J$$$$$$r:   rr   c                  0    e Zd ZU dZdZded<   dZded<   dS )CKLookupInfoz5Contact information for user lookup (email or phone).NrO   emailAddressphoneNumber)rR   rS   rT   rU   rw   rV   rx   rW   r:   r.   rv   rv      s:         ??"&L&&&&!%K%%%%%%r:   rv   c                  >    e Zd ZU dZdZded<   dZded<   dZded<   dS )	CKUserIdentityz9Complete user identity with name and contact information.NrO   r[   zOptional[CKNameComponents]nameComponentszOptional[CKLookupInfo]
lookupInfo)rR   rS   rT   rU   r[   rV   r{   r|   rW   r:   r.   rz   rz      sK         CC$(N((((15N5555)-J------r:   rz   c                      e Zd ZdZdS )CKParticipantProtectionInfoz+Participant-scoped protectionInfo envelope.NrR   rS   rT   rU   rW   r:   r.   r~   r~      s        5555r:   r~   c                      e Zd ZU dZdZded<   dZded<   dZded<   dZded<   dZ	ded	<   dZ
ded
<   dZded<   dZded<   dZded<   dZded<   dZded<   dZded<   dS )CKParticipantzFPerson sharing a record with permissions, status, and protection info.NrO   participantIdzOptional[CKUserIdentity]userIdentityr?   acceptanceStatus
permission
customRoleOptional[bool]isApprovedRequesterorgUserOptional[int]publicKeyVersionoutOfNetworkPrivateKeyoutOfNetworkKeyTypez%Optional[CKParticipantProtectionInfo]protectionInfo)rR   rS   rT   rU   r   rV   r   r?   r   r   r   r   r   r   r   r   r   rW   r:   r.   r   r      s         PP#'M''''-1L1111D&***** $J$$$$ $J$$$$*....."G""""&*****,00000)-----<@N@@@@@@r:   r   c                      e Zd ZdZdS )	CKPCSInfoz6Top-level PCS envelope used by shared-record metadata.Nr   rW   r:   r.   r   r      s        @@@@r:   r   c                  :    e Zd ZU dZded<   dZded<   dZded<   dS )	CKReferencezY
    Value inside REFERENCE / REFERENCE_LIST typed fields (both request & response).
    r!   r_   NrO   actionro   rp   )rR   rS   rT   rU   rV   r   rp   rW   r:   r.   r   r      sI           OOO F    !%F%%%%%%r:   r   c                      e Zd ZdZdS )_CKFieldBasezGBase class for CloudKit field type wrappers with discriminator support.Nr   rW   r:   r.   r   r     s        QQ 	Dr:   r   c                  (    e Zd ZU dZded<   ded<   dS )CKTimestampFieldz1Milliseconds-since-epoch timestamp field wrapper.zLiteral['TIMESTAMP']r?   MillisDateTimeOrNonevalueNr`   rW   r:   r.   r   r     s<         ;;     r:   r   c                  (    e Zd ZU dZded<   ded<   dS )CKInt64Fieldz$64-bit signed integer field wrapper.Literal['INT64']r?   r   r   Nr`   rW   r:   r.   r   r     s+         ..JJJJJr:   r   c                  (    e Zd ZU dZded<   ded<   dS )CKEncryptedBytesFieldz.Base64-encoded encrypted binary field wrapper.zLiteral['ENCRYPTED_BYTES']r?   r   r   Nr`   rW   r:   r.   r   r     s0         88$$$$r:   r   c                  (    e Zd ZU dZded<   ded<   dS )CKReferenceFieldz%Reference to another CloudKit record.Literal['REFERENCE']r?   zOptional[CKReference]r   Nr`   rW   r:   r.   r   r   $  s0         //      r:   r   c                  (    e Zd ZU dZded<   ded<   dS )CKReferenceListFieldz-List of references to other CloudKit records.Literal['REFERENCE_LIST']r?   List[CKReference]r   Nr`   rW   r:   r.   r   r   +  s0         77####r:   r   c                  6    e Zd ZU dZded<   ded<   dZded<   dS )	CKStringFieldz1String value field wrapper, optionally encrypted.Literal['STRING']r?   rO   r   Nr   isEncryptedrR   rS   rT   rU   rV   r   rW   r:   r.   r   r   4  sA         ;;"&K&&&&&&r:   r   c                  (    e Zd ZU dZded<   ded<   dS )CKStringListFieldz$List of string values field wrapper.Literal['STRING_LIST']r?   	List[str]r   Nr`   rW   r:   r.   r   r   <  s0         ..    r:   r   c                  h    e Zd ZU dZdZded<   dZded<   dZded<   dZded<   dZ	ded	<   dZ
d
ed<   dS )CKAssetTokenz;Asset token with download URL, checksums, and wrapping key.NrO   fileChecksumreferenceChecksumwrappingKeydownloadURLrj   downloadedDatar   size)rR   rS   rT   rU   r   rV   r   r   r   r   r   rW   r:   r.   r   r   D  s         EE #'L&&&&'+++++!%K%%%%!%K%%%%,0N0000Dr:   r   c                  (    e Zd ZU dZded<   ded<   dS )CKAssetIDFieldz5Asset ID field wrapper referencing an asset by token.zLiteral['ASSETID']r?   r   r   Nr`   rW   r:   r.   r   r   P  s0         ??r:   r   c                  (    e Zd ZU dZded<   ded<   dS )CKAssetFieldz*Asset field wrapper for inline asset data.zLiteral['ASSET']r?   r   r   Nr`   rW   r:   r.   r   r   X  s0         44r:   r   c                  6    e Zd ZU dZded<   ded<   dZded<   dS )	CKDoubleFieldzLFloating-point field wrapper, optionally encrypted (e.g. for location data).zLiteral['DOUBLE']r?   r    r   Nr   r   r   rW   r:   r.   r   r   _  s>         VVLLL"&K&&&&&&r:   r   c                  (    e Zd ZU dZded<   ded<   dS )CKBytesFieldz1Raw binary field wrapper as base64-encoded bytes.zLiteral['BYTES']r?   r   r   Nr`   rW   r:   r.   r   r   h  s2         ;; r:   r   c                  (    e Zd ZU dZded<   ded<   dS )CKDoubleListFieldz,List of floating-point values field wrapper.zLiteral['DOUBLE_LIST']r?   zList[float]r   Nr`   rW   r:   r.   r   r   p  s0         66    r:   r   c                  (    e Zd ZU dZded<   ded<   dS )CKInt64ListFieldz,List of 64-bit integer values field wrapper.zLiteral['INT64_LIST']r?   z	List[int]r   Nr`   rW   r:   r.   r   r   w  s0         66r:   r   c                  (    e Zd ZU dZded<   ded<   dS )CKAssetIDListFieldz&List of asset ID tokens field wrapper.zLiteral['ASSETID_LIST']r?   zList[CKAssetToken]r   Nr`   rW   r:   r.   r   r   ~  s2         00 "!!!r:   r   c                  (    e Zd ZU dZded<   ded<   dS )CKUnknownListFieldz:Fallback list field wrapper for unexpected CloudKit types.zLiteral['UNKNOWN_LIST']r?   zList[JsonValue]r   Nr`   rW   r:   r.   r   r     s2         DD "!!!r:   r   c                  (    e Zd ZU dZded<   ded<   dS )CKPassthroughFieldzAGeneric field wrapper for unknown or future CloudKit field types.r!   r?   r   r   Nr`   rW   r:   r.   r   r     s-         KKIIIr:   r   >   ASSETBYTESINT64DOUBLESTRINGASSETID	REFERENCE	TIMESTAMP
INT64_LISTDOUBLE_LISTSTRING_LISTASSETID_LISTUNKNOWN_LISTREFERENCE_LISTENCRYPTED_BYTESzfrozenset[str]
KNOWN_TAGSr?   )discriminator)r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   zdict[str, type[_CKFieldBase]]_KNOWN_CK_FIELD_MODELSc                      e Zd ZU dZded<   ed             Zedd            Zd Z e	d	
          e
d                         ZdS )CKFieldOpenux  
    Public API for field wrappers:
      - `.value` (preferred): the decoded inner `value` of the CK wrapper
      - `.type_tag`: the CloudKit `type` string (e.g., "TIMESTAMP", "INT64_LIST")
      - `.unwrap()`: return the inner typed wrapper instance (e.g., `CKTimestampField`)

    Implementation detail: `.root` is internal — avoid relying on it outside this class.
    z'Union[KnownCKField, CKPassthroughField]rootc                .    t          | j        dd          S )z0Retrieve the inner value from the field wrapper.r   Ngetattrr   selfs    r.   r   zCKFieldOpen.value  s     ty'4000r:   r1   rO   c                .    t          | j        dd          S )z@Retrieve the CloudKit type discriminator from the field wrapper.r?   Nr   r   s    r.   type_tagzCKFieldOpen.type_tag  s     ty&$///r:   c                    | j         S )zReturn the inner typed wrapper (e.g., CKTimestampField).
        Public escape hatch; prefer `.value` for most use-cases.
        )r   r   s    r.   unwrapzCKFieldOpen.unwrap  s     yr:   beforemodec                   t          |t                    r|                    d          nd}t          |t                    r|S t          |t                    r)|t          v r t
          |                             |          S t          |t                    r"d|v rd|v rt                              |          S t          |rt          |          nd|          S )a{  
        Ensure nested contexts (e.g., values inside Dict[str, CKFieldOpen]) use the same
        discriminator-based dispatch as our explicit model_validate(...) call.

        IMPORTANT: For RootModel, 'before' must return the *underlying* value, not
        a dict like {'root': ...}; returning a dict breaks the discriminated union
        when this model is nested.
        r?   Nr   UNKNOWN)r?   r   )	r   dictgetr   r   r   model_validater   r!   )clsobjts      r.   _dispatch_beforezCKFieldOpen._dispatch_before  s      *#t44>CGGFOOO$ c<(( 	J c4   	AQ*__)!,;;C@@@ c4   	:Vs]]w#~~%44S999 "'As1vvv	MMMMr:   N)r1   rO   )rR   rS   rT   rU   rV   propertyr   r   r   r   classmethodr   rW   r:   r.   r   r     s           21111 1 X1
 0 0 0 X0
   _(###N N [ $#N N Nr:   r   c                  :     e Zd ZdZddZ fdZdd	Zdd
Z xZS )CKFieldsa
  
    Dict-like container that also allows attribute access, e.g.:
        rec.fields.ModificationDate.value
    Falls back to normal dict behavior for [] access.

    Public surface:
      - Attribute access: `rec.fields.<FieldName>.value`
      - Mapping access:   `rec.fields["FieldName"].value`
      - Helpers:          `get_field()`, `get_value()`

    Implementation detail: `.root` is **internal**; client code should not use it.
    Use `.unwrap()` if you need the inner typed wrapper for `isinstance` checks.
    namer!   r1   r   c                ~    	 t                               | |          S # t          $ r}t          |          |d}~ww xY w)zARetrieve field value by attribute name instead of dictionary key.N)r   __getitem__KeyErrorAttributeError)r   r   es      r.   __getattr__zCKFields.__getattr__*  sL    	.##D$/// 	. 	. 	. &&A-	.s    
<7<c                    t          t                                                                }t          |t          |                                           z            S )z0List available field names for attribute access.)setsuper__dir__sortedkeys)r   base	__class__s     r.   r  zCKFields.__dir__1  sA    577??$$%%dS---...r:   keyc                    |                      |          }|dS t          |d          r|                                n|S )z=Retrieve the inner typed field wrapper for isinstance checks.Nr   )r   hasattrr   r   r  fs      r.   	get_fieldzCKFields.get_field6  s<    HHSMM94$Q118qxxzzzq8r:   c                V    |                      |          }|dnt          |dd          S )z-Retrieve the decoded value of a field by key.Nr   )r  r   r	  s      r.   	get_valuezCKFields.get_value>  s-    NN3yttga$&?&??r:   )r   r!   r1   r   )r  r!   )	rR   rS   rT   rU   r   r  r  r  __classcell__)r  s   @r.   r   r     s         . . . ./ / / / /
9 9 9 9@ @ @ @ @ @ @ @r:   r   c                    t          | |          r| S t          | t                    r' |d |                                 D                       S | S )zCValidate a raw field mapping into the requested CK field container.c                J    i | ] \  }}|t                               |          !S rW   )_CK_FIELD_OPEN_ADAPTERvalidate_python).0kvals      r.   
<dictcomp>z)_coerce_field_mapping.<locals>.<dictcomp>J  s-    TTT3Q&66s;;TTTr:   )r   r   items)r+   mapping_clss     r.   _coerce_field_mappingr  D  s_    ![!! !T 
{TT!''))TTT
 
 	
 Hr:   c                  "   e Zd ZU dZded<   ded<    ee          Zded<    edd	          e	d
                         Z
 ed	          d             Z ee          Zded<   dZded<   dZded<   dZded<   dZded<   dZded<   dZded<   dZded<   dZded<   dZded<   dZded <   dZded!<   dZd"ed#<   dZd"ed$<   dZd"ed%<   dZded&<   dZd'ed(<   dZd'ed)<   dZ d*ed+<   dZ!d*ed,<   dZ"ded-<   dZ#d.ed/<   dZ$ded0<   dZ%ded1<   dZ&d2ed3<   dS )4CKRecorda  
    A CloudKit record as returned in /records/query (or other endpoints).

    The 'fields' map contains app-level fields by **PascalCase** names
    (e.g., TitleEncrypted, ModificationDate, Deleted, Folder, Folders, ...),
    each wrapped in a CKField type above.
    r!   r_   
recordTypedefault_factoryr   fieldsr   r   c                ,    t          |t                    S )z
        Ensure the mapping is validated item-by-item to CKFieldOpen
        and wrapped in CKFields to enable attribute access DX.
        )r  r   r   r+   s     r.   _coerce_fieldszCKRecord._coerce_fieldsc  s     %Q111r:   afterc           	        | j                                         D ]\  }}t          |t                    r|                    d          s0t          |d          r|                                n|}t          |dd          }|dk    rn|dk    rt          |dd          d	u rt          d
| d| j	        d|          | S )zValidate encrypted-field wrappers against observed CloudKit shapes.

        Most `*Encrypted` fields use ENCRYPTED_BYTES, but shared CloudKit
        records can legitimately carry STRING wrappers with `isEncrypted=true`.
        	Encryptedr   r?   Nr   r   r   FTzField 'z' on recordType z> must be ENCRYPTED_BYTES or STRING with isEncrypted=true, got )
r  r  r   r!   endswithr  r   r   r%   r  )r   r  wrapperinnertags        r.   _validate_encrypted_fieldsz#CKRecord._validate_encrypted_fieldsl  s     !K--// 	 	LCc3'' s||K/H/H (/(B(BOGNN$$$E%..C'''h75-#G#G4#O#O#  t      r:   Dict[str, JsonValue]pluginFieldsNrO   recordChangeTagzOptional[CKAuditInfo]createdmodifiedr   deletedro   rp   zOptional[CKParent]parentrg   zOptional[CKStableUrl]	stableUrl	shortGUIDzOptional[CKShare]sharepublicPermissionzOptional[List[CKParticipant]]participants
requestersblockeddenyAccessRequestszOptional[CKParticipant]ownercurrentUserParticipantzOptional[CKPCSInfo]
invitedPCSselfAddedPCSrd   zOptional[CKChainProtectionInfo]chainProtectionInfochainParentKeychainPrivateKeyzOptional[SecsOrMillisDateTime]expirationTime)'rR   rS   rT   rU   rV   r   r   r  r   r   r"  r   r*  r   r,  r-  r.  r/  r0  rp   r1  rg   r2  r3  r4  r5  r6  r7  r8  r9  r:  r;  r<  r=  rd   r>  r?  r@  rA  rW   r:   r.   r  r  T  st          OOOOOO uX666F6666_XH---2 2 [ .-2 _'"""  #"8 */t)D)D)DLDDDD &*O))))%)G))))&*H****"G""""!%F%%%%!%F%%%% (,++++'+I++++#I####  $E####&*****26L666604J4444-1G1111)-----%)E))))6:::::&*J****(,L,,,,$(N(((( <@????$(N((((%)O)))) 6:N999999r:   r  c                      e Zd ZU dZded<   dS )CKWriteParentz4Write-side parent reference embedded under a record.r!   r_   Nr`   rW   r:   r.   rC  rC    s         >>OOOOOr:   rC  c                      e Zd ZdZdS )CKWriteFieldsz>Field mapping specialized for CloudKit record modify requests.Nr   rW   r:   r.   rE  rE    s        HHDr:   rE  c                      e Zd ZU dZded<   ded<    ee          Zded<    ee          Z	ded	<   d
Z
ded<   d
Zded<   d
Zded<    edd          ed                         Zd
S )CKWriteRecordz
    CloudKit record shape used in modify requests.

    Keep this narrower than CKRecord: only request-side fields that are
    actually serialized on writes belong here.
    r!   r_   r  r  rE  r  r+  r,  NrO   r-  zOptional[CKWriteParent]r1  ro   rp   r   r   c                ,    t          |t                    S )z=Convert raw field mapping into typed CKWriteFields container.)r  rE  r!  s     r.   r"  zCKWriteRecord._coerce_fields  s     %Q666r:   )rR   rS   rT   rU   rV   r   rE  r  r   r,  r-  r1  rp   r   r   r"  rW   r:   r.   rG  rG    s           OOOOOO!E-@@@F@@@@).t)D)D)DLDDDD%)O))))&*F****!%F%%%%_XH---7 7 [ .-7 7 7r:   rG  c                  :    e Zd ZU dZded<   dZded<   dZded<   dS )CKErrorItemz
    Error item possibly present inside `records[]` when a per-record operation fails.
    Additional server-provided properties will be preserved via CKModel(extra="allow").
    r!   serverErrorCodeNrO   reasonr_   )rR   rS   rT   rU   rV   rL  r_   rW   r:   r.   rJ  rJ    sL          
  F     $J$$$$$$r:   rJ  c                  6    e Zd ZU dZded<   ded<   dZded<   dS )	CKTombstoneRecorduA  
    A 'tombstone' entry returned by CloudKit to indicate a deleted record.
    Tombstones intentionally omit `recordType` and `fields` — they only assert
    that a record with `recordName` existed but has since been deleted.
    Additional server-provided properties will be preserved via CKModel(extra="allow").
    r!   r_   zLiteral[True]r0  Nro   rp   )rR   rS   rT   rU   rV   rp   rW   r:   r.   rN  rN    sD           OOO!%F%%%%%%r:   rN  c                  R    e Zd ZU dZ ee          Zded<   dZded<   dZ	ded<   dS )	CKQueryResponsez
    Top-level response from /records/query:
    - records: list of CKRecord
    - continuationMarker: optional paging token (present if more results exist)
    r  5List[Union[CKRecord, CKTombstoneRecord, CKErrorItem]]recordsNrO   continuationMarker	syncToken)
rR   rS   rT   rU   r   listrR  rV   rS  rT  rW   r:   r.   rP  rP    sw           FKUF F FG     )-,,,,  $I######r:   rP  c                  2    e Zd ZdZdZdZdZdZdZdZ	dZ
d	Zd
S )CKComparatorz+CloudKit query filter comparison operators.EQUALSINCONTAINS_ANY	LESS_THANLESS_THAN_OR_EQUALSGREATER_THANGREATER_THAN_OR_EQUALSBEGINS_WITHN)rR   rS   rT   rU   rX  IN_rZ  r[  r\  r]  r^  r_  rW   r:   r.   rW  rW    s>        55F
C!LI/!L5KKKr:   rW  c                      e Zd ZdZdS )_CKFilterValueBasez=Base class for filter value wrappers with type discriminator.Nr   rW   r:   r.   rb  rb    s        GGDr:   rb  c                  (    e Zd ZU dZded<   ded<   dS )
CKFVStringz'String literal value in a query filter.r   r?   r!   r   Nr`   rW   r:   r.   rd  rd    s+         11JJJJJr:   rd  c                  (    e Zd ZU dZded<   ded<   dS )	CKFVInt64z(Integer literal value in a query filter.r   r?   r   r   Nr`   rW   r:   r.   rf  rf  "  s+         22JJJJJr:   rf  c                  (    e Zd ZU dZded<   ded<   dS )CKFVStringListz(List of string values in a query filter.r   r?   r   r   Nr`   rW   r:   r.   rh  rh  )  s0         22    r:   rh  c                  (    e Zd ZU dZded<   ded<   dS )CKFVReferencez)Record reference value in a query filter.r   r?   r   r   Nr`   rW   r:   r.   rj  rj  0  s0         33r:   rj  c                  (    e Zd ZU dZded<   ded<   dS )CKFVReferenceListz,List of record references in a query filter.r   r?   r   r   Nr`   rW   r:   r.   rl  rl  7  s0         66####r:   rl  c                  ,    e Zd ZU dZded<   dZded<   dS )CKQuerySortByzU
    Sort directive. Example:
      {"fieldName": "modTime", "ascending": false}
    r!   	fieldNameNr   	ascending)rR   rS   rT   rU   rV   rp  rW   r:   r.   rn  rn  J  s8          
 NNN $I$$$$$$r:   rn  c                  2    e Zd ZU dZded<   ded<   ded<   dS )	CKQueryFilterBya  
    Filter clause. Examples:

    STRING equality:
      {"comparator": "EQUALS",
       "fieldName": "indexName",
       "fieldValue": {"value": "recents", "type": "STRING"}}

    REFERENCE equality:
      {"comparator": "EQUALS",
       "fieldName": "reference",
       "fieldValue": {"value": {"recordName": "...", "action": "VALIDATE"},
                      "type": "REFERENCE"}}
    zUnion[CKComparator, str]
comparatorr!   ro  CKFilterValue
fieldValueNr`   rW   r:   r.   rr  rr  T  s?           )(((NNNr:   rr  c                  :    e Zd ZU dZded<   dZded<   dZded<   dS )	CKQueryObjectz
    The 'query' object inside the request.

    recordType can be an app-defined pseudo type like "SearchIndexes" or "pinned"
    or a real record type.
    r!   r  NzOptional[List[CKQueryFilterBy]]filterByzOptional[List[CKQuerySortBy]]sortBy)rR   rS   rT   rU   rV   rx  ry  rW   r:   r.   rw  rw  i  sI           OOO04H4444,0F000000r:   rw  c                  :    e Zd ZU dZded<   dZded<   dZded<   dS )CKZoneIDReqz8Zone identifier for requests (without redundant fields).r!   rN   NrO   rQ   rP   )rR   rS   rT   rU   rV   rQ   rP   rW   r:   r.   r{  r{  w  sC         BBMMM"H""""%)O))))))r:   r{  c                  d    e Zd ZU dZded<   dZded<   dZded<   dZd	ed
<   dZded<   dZ	ded<   dS )CKQueryRequesta  
    Top-level /records/query request payload.

    ``zoneID`` is optional because CloudKit also accepts a ``zoneWide``-style
    query (no specific zone, scans all zones in the database) used by the
    Invites service to enumerate per-event zones in one round trip.
    rw  queryNzOptional[CKZoneIDReq]rp   Optional[List[str]]desiredKeysr   resultsLimitrO   rS  r   zoneWide)
rR   rS   rT   rU   rV   rp   r  r  rS  r  rW   r:   r.   r}  r}    s           $(F(((('+K++++"&L&&&&(,,,,,#H######r:   r}  c                      e Zd ZU dZded<   dS )CKLookupDescriptorz$Specifies a record to fetch by name.r!   r_   Nr`   rW   r:   r.   r  r    s         ..OOOOOr:   r  c                  6    e Zd ZU dZded<   ded<   dZded<   dS )	CKLookupRequestz5Payload for fetching specific records by their names.zList[CKLookupDescriptor]rR  r{  rp   Nr  r  )rR   rS   rT   rU   rV   r  rW   r:   r.   r  r    sA         ??%%%%'+K++++++r:   r  c                  ,    e Zd ZU dZded<   dZded<   dS )CKLookupResponsez6Response containing records fetched by lookup request.rQ  rR  NrO   rT  )rR   rS   rT   rU   rV   rT  rW   r:   r.   r  r    s5         @@BBBB#I######r:   r  c                  :    e Zd ZU dZded<   dZded<   dZded<   dS )	CKZoneListZonez
    One zone entry returned by /zones/list.

    Photos uses this as the primary source of truth for available private/shared
    libraries, so keep the model permissive while typing the fields we depend on.
    rM   rp   NrO   rT  r   r0  )rR   rS   rT   rU   rV   rT  r0  rW   r:   r.   r  r    sL           #I####"G""""""r:   r  c                  6    e Zd ZU dZ ee          Zded<   dS )CKZoneListResponsez#Top-level envelope for /zones/list.r  zList[CKZoneListZone]zonesNrR   rS   rT   rU   r   rU  r  rV   rW   r:   r.   r  r    s6         --"'%"="="=E======r:   r  c                  ,    e Zd ZU dZded<   dZded<   dS )CKDatabaseChangesZonez
    One zone entry returned by /changes/database.

    This is a database-scoped change feed used to identify which zones changed
    before issuing per-zone /changes/zone requests.
    rM   rp   Nr   r0  )rR   rS   rT   rU   rV   r0  rW   r:   r.   r  r    s;           "G""""""r:   r  c                  R    e Zd ZU dZ ee          Zded<   dZded<   dZ	ded	<   dS )
CKDatabaseChangesResponsez)Top-level envelope for /changes/database.r  zList[CKDatabaseChangesZone]r  Nr   
moreComingrO   rT  )
rR   rS   rT   rU   r   rU  r  rV   r  rT  rW   r:   r.   r  r    sX         33).t)D)D)DEDDDD!%J%%%%#I######r:   r  c                  X    e Zd ZU dZ ee          Zded<   dZded<   ded	<   d
ed<   dS )CKZoneChangesZonez
    One zone entry inside the /changes/zone response.

    Observed shape:
      - Always has: records[], zoneID, syncToken
      - moreComing is present but sometimes null (treat as Optional[bool])
    r  rQ  rR  Nr   r  r!   rT  rM   rp   )	rR   rS   rT   rU   r   rU  rR  rV   r  rW   r:   r.   r  r    sx           FKUF F FG     "&J%%%%NNNr:   r  c                  6    e Zd ZU dZ ee          Zded<   dS )CKZoneChangesResponsez\
    Top-level envelope for /private/changes/zone (and /shared/changes/zone) responses.
    r  zList[CKZoneChangesZone]r  Nr  rW   r:   r.   r  r    s<           &+U4%@%@%@E@@@@@@r:   r  c                  V    e Zd ZU dZded<   dZded<   dZded<   dZded	<   dZd
ed<   dS )CKZoneChangesZoneReqa  
    One zone request entry for /changes/zone.

    Observed keys:
      - zoneID: includes zoneName (e.g., "Notes" or "Reminders"), sometimes zoneType and ownerRecordName (for shared)
      - desiredKeys: list of field names to project (duplicates allowed, order preserved)
      - desiredRecordTypes: list of record types to include
      - syncToken: optional paging token (base64-like string)
      - reverse: optional bool
    rM   rp   Nr  r  desiredRecordTypesrO   rT  r   reverse)	rR   rS   rT   rU   rV   r  r  rT  r  rW   r:   r.   r  r    so         	 	 '+K++++.22222#I####"G""""""r:   r  c                  ,    e Zd ZU dZded<   dZded<   dS )CKZoneChangesRequestz>Payload for fetching zone changes since a specific sync token.zList[CKZoneChangesZoneReq]r  Nr   r  )rR   rS   rT   rU   rV   r  rW   r:   r.   r  r    s5         HH%%%%"&L&&&&&&r:   r  c                  (    e Zd ZU dZded<   ded<   dS )CKModifyOperationzCSingle record operation in a modify request (create/update/delete).z^Literal['create', 'update', 'forceUpdate', 'replace', 'forceReplace', 'delete', 'forceDelete']operationTyperG  recordNr`   rW   r:   r.   r  r    s:         MM    r:   r  c                  6    e Zd ZU dZded<   ded<   dZded<   dS )	CKModifyRequestz(Payload for modifying records in a zone.zList[CKModifyOperation]
operationsr{  rp   Nr   atomic)rR   rS   rT   rU   rV   r  rW   r:   r.   r  r  +  sA         22''''!F!!!!!!r:   r  c                  D    e Zd ZU dZ ee          Zded<   dZded<   dS )CKModifyResponsez:Response containing records after modification operations.r  rQ  rR  NrO   rT  )	rR   rS   rT   rU   r   rU  rR  rV   rT  rW   r:   r.   r  r  3  s[         DDEJUF F FG      $I######r:   r  N)r0   r   r1   r   )qrU   
__future__r   r   r   enumr   typingr   r   r	   r
   r   r   pydanticr   r   r   r   r   r   r   r   r   r   r  r   r'   r   rV   r/   r9   r   rZ   r   rI   rK   SecsOrMillisDateTimerM   rY   r^   rb   ri   rn   rr   rv   rz   r~   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   	frozensetr   KnownCKFieldr   r   r  r   r!   r   r  r  rC  rE  rG  rJ  rN  rP  rW  rb  rd  rf  rh  rj  rl  rt  rn  rr  rw  r{  r}  r  r  r  r  r  r  r  r  r  r  r  r  r  r  rW   r:   r.   <module>r     s    
 # " " " " " ' ' ' ' ' ' ' '       B B B B B B B B B B B B B B B B                              #        6& & & & O())OJC6BBBNI6UVVWWY !XOLLMMO66  
 N'K	
 	
  &  (    !O())OH#@@@NI6PQQRRT # # # # #w # # ## # # # #' # # #    w   , , , , ,' , , ,' ' ' ' 'G ' ' '	& 	& 	& 	& 	&g 	& 	& 	&% % % % %w % % %& & & & &7 & & &. . . . .W . . .6 6 6 6 6"7 6 6 6A A A A AG A A A"A A A A A% A A A& & & & &' & & &	 	 	 	 	7 	 	 	    |       <       L   ! ! ! ! !| ! ! !    <   ' ' ' ' 'L ' ' '       	 	 	 	 	7 	 	 	    \       <   ' ' ' ' 'L ' ' '    <              |                         'Y   
    0 		" 
E#!, ",!*$$"&&9 9     09N 9N 9N 9N 9N)E,0B"BCD 9N 9N 9Nx %[11 &@ &@ &@ &@ &@tC$% &@ &@ &@R   X: X: X: X: X:w X: X: X:v    G   	 	 	 	 	H 	 	 	7 7 7 7 7G 7 7 74% % % % %' % % %
& 
& 
& 
& 
& 
& 
& 
&$ $ $ $ $g $ $ $,
  
  
  
  
 3 
  
  
 	 	 	 	 	 	 	 	    #       "       '       &       *    			 
E!	% % % % %G % % %    g   *
1 
1 
1 
1 
1G 
1 
1 
1* * * * *' * * *$ $ $ $ $W $ $ $&       , , , , ,g , , ,$ $ $ $ $w $ $ $
# 
# 
# 
# 
#W 
# 
# 
#> > > > > > > >	# 	# 	# 	# 	#G 	# 	# 	#$ $ $ $ $ $ $ $       "A A A A AG A A A# # # # #7 # # #(' ' ' ' '7 ' ' '       " " " " "g " " "$ $ $ $ $w $ $ $ $ $r:   