o
    l>j                     @  s(  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d ZdddZeeeeeee ddedddf Z!eee edd edd e ddeddgddf Z"dd  Z#dd!d"Z$eeee#ee$e ddedd#df Z%G d$d% d%eZ&G d&d' d'eZ'G d(d) d)eZ(G d*d+ d+eZ)G d,d- d-eZ*G d.d/ d/eZ+G d0d1 d1eZ,G d2d3 d3eZ-G d4d5 d5eZ.G d6d7 d7e*Z/G d8d9 d9eZ0G d:d; d;e*Z1G d<d= d=eZ2G d>d? d?eZ3G d@dA dAe3Z4G dBdC dCe3Z5G dDdE dEe3Z6G dFdG dGe3Z7G dHdI dIe3Z8G dJdK dKe3Z9G dLdM dMe3Z:G dNdO dOeZ;G dPdQ dQe3Z<G dRdS dSe3Z=G dTdU dUe3Z>G dVdW dWe3Z?G dXdY dYe3Z@G dZd[ d[e3ZAG d\d] d]e3ZBG d^d_ d_e3ZCG d`da dae3ZDeEh dbZFdcedd< eee4e5e6e7e8e9e:e<e=e>e?e@eAeBeCf ededff ZGe4e5e6e7e8e9e:e<e=e>e?e@eAeBeCdgZHdhedi< G djdk dkeeeGeDf  ZIeeIZJG dldm dmeKeLeIf ZMdndo ZNG dpdq dqeZOG drds dseZPG dtdu dueMZQG dvdw dweZRG dxdy dyeZSG dzd{ d{eZTG d|d} d}eZUG d~d deLeZVG dd deZWG dd deWZXG dd deWZYG dd deWZZG dd deWZ[G dd deWZ\eeeXeYeZe[e\f ededff Z]G dd deZ^G dd deZ_G dd deZ`G dd deZaG dd deZbG dd deZcG dd deZdG dd deZeG dd deZfG dd deZgG dd deZhG dd deZiG dd deZjG dd deZkG dd deZlG dd deZmG dd deZnG dd deZoG dd 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              
   C  s   t | ttfrt| }n(t | tr0|  }|drd S zt|}W n tttfy/   Y d S w td|t	v s<|t
kr>d S ztj|d tjdW S  tttfyV   Y d S 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sv r,   T/home/thesage/.local/lib/python3.10/site-packages/pyicloud/common/cloudkit/models.py_from_millis_or_none)   s&   


r.   dtr   returnr   c                 C  s(   | j d u r| jtjd} t|  d S )Ntzinfoi  r2   replacer   r'   r   	timestampr/   r,   r,   r-   
_to_millisD   s   
r7   json)return_type	when_usedintegerzmilliseconds since Unix epoch)typedescriptionc                 C     | d u rd S t | S N)r.   r)   r,   r,   r-   <lambda>U       rA   c                 C  r>   r?   )r7   r@   r,   r,   r-   rA   W   rB   nullz.milliseconds since Unix epoch or null sentinelc              
   C  s   t | ttfrt| }nt | tr'zt|  }W n tttfy&   Y d S w tdzt|dk r;t	j
|tjdW S t	j
|d tjdW S  tttfyR   Y d S 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*   r,   r,   r-   _from_secs_or_millisf   s    

rE   c                 C  s$   | j d u r| jtjd} t|  S )Nr1   r3   r6   r,   r,   r-   _to_secsz   s   
rF   zseconds since Unix epochc                   @  2   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__rK   rL   r,   r,   r,   r-   rH      
   
 rH   c                   @  rG   )CKAuditInfozK
    Appears as `created` / `modified` at the record level (response).
    MillisDateTimer5   NrJ   userRecordNamedeviceID)rM   rN   rO   rP   rQ   rU   rV   r,   r,   r,   r-   rS      
   
 rS   c                   @     e Zd ZU dZded< dS )CKParentz1References a parent record in a record hierarchy.r   
recordNameNrM   rN   rO   rP   rQ   r,   r,   r,   r-   rY         
 rY   c                   @  sN   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.NrJ   
routingKeyshortTokenHashprotectedFullTokenencryptedPublicSharingKeydisplayedHostname)
rM   rN   rO   rP   r^   rQ   r_   r`   ra   rb   r,   r,   r,   r-   r]      s   
 r]   c                   @  *   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]bytesrJ   pcsChangeTag)rM   rN   rO   rP   rf   rQ   rg   r,   r,   r,   r-   rd         
 rd   c                   @  rc   )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.
    NrJ   rZ   Optional[CKZoneID]zoneID)rM   rN   rO   rP   rZ   rQ   rk   r,   r,   r,   r-   ri      s   
 ri   c                   @  *   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.NrJ   	givenName
familyName)rM   rN   rO   rP   rn   rQ   ro   r,   r,   r,   r-   rm      rh   rm   c                   @  rl   )CKLookupInfoz5Contact information for user lookup (email or phone).NrJ   emailAddressphoneNumber)rM   rN   rO   rP   rq   rQ   rr   r,   r,   r,   r-   rp      rh   rp   c                   @  s6   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.NrJ   rU   zOptional[CKNameComponents]nameComponentszOptional[CKLookupInfo]
lookupInfo)rM   rN   rO   rP   rU   rQ   rt   ru   r,   r,   r,   r-   rs      s
   
 rs   c                   @     e Zd ZdZdS )CKParticipantProtectionInfoz+Participant-scoped protectionInfo envelope.NrM   rN   rO   rP   r,   r,   r,   r-   rw          rw   c                   @  s   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.NrJ   participantIdzOptional[CKUserIdentity]userIdentityr<   acceptanceStatus
permission
customRoleOptional[bool]isApprovedRequesterorgUserOptional[int]publicKeyVersionoutOfNetworkPrivateKeyoutOfNetworkKeyTypez%Optional[CKParticipantProtectionInfo]protectionInfo)rM   rN   rO   rP   r{   rQ   r|   r<   r}   r~   r   r   r   r   r   r   r   r,   r,   r,   r-   rz      s   
 rz   c                   @  rv   )	CKPCSInfoz6Top-level PCS envelope used by shared-record metadata.Nrx   r,   r,   r,   r-   r      ry   r   c                   @  2   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   rZ   NrJ   actionrj   rk   )rM   rN   rO   rP   rQ   r   rk   r,   r,   r,   r-   r      rW   r   c                   @  rv   )_CKFieldBasezGBase class for CloudKit field type wrappers with discriminator support.Nrx   r,   r,   r,   r-   r     s    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[   r,   r,   r,   r-   r        
 r   c                   @  r   )CKInt64Fieldz$64-bit signed integer field wrapper.Literal['INT64']r<   r   r   Nr[   r,   r,   r,   r-   r     r   r   c                   @  r   )CKEncryptedBytesFieldz.Base64-encoded encrypted binary field wrapper.zLiteral['ENCRYPTED_BYTES']r<   r   r   Nr[   r,   r,   r,   r-   r     r   r   c                   @  r   )CKReferenceFieldz%Reference to another CloudKit record.Literal['REFERENCE']r<   zOptional[CKReference]r   Nr[   r,   r,   r,   r-   r   $  r   r   c                   @  r   )CKReferenceListFieldz-List of references to other CloudKit records.Literal['REFERENCE_LIST']r<   List[CKReference]r   Nr[   r,   r,   r,   r-   r   +  r   r   c                   @  .   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<   rJ   r   Nr   isEncryptedrM   rN   rO   rP   rQ   r   r,   r,   r,   r-   r   4  
   
 r   c                   @  r   )CKStringListFieldz$List of string values field wrapper.Literal['STRING_LIST']r<   	List[str]r   Nr[   r,   r,   r,   r-   r   <  r   r   c                   @  sZ   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.NrJ   fileChecksumreferenceChecksumwrappingKeydownloadURLre   downloadedDatar   size)rM   rN   rO   rP   r   rQ   r   r   r   r   r   r,   r,   r,   r-   r   D  s   
 r   c                   @  r   )CKAssetIDFieldz5Asset ID field wrapper referencing an asset by token.zLiteral['ASSETID']r<   r   r   Nr[   r,   r,   r,   r-   r   P  r   r   c                   @  r   )CKAssetFieldz*Asset field wrapper for inline asset data.zLiteral['ASSET']r<   r   r   Nr[   r,   r,   r,   r-   r   X  r   r   c                   @  r   )	CKDoubleFieldzLFloating-point field wrapper, optionally encrypted (e.g. for location data).zLiteral['DOUBLE']r<   r   r   Nr   r   r   r,   r,   r,   r-   r   _  s
   
 r   c                   @  r   )CKBytesFieldz1Raw binary field wrapper as base64-encoded bytes.zLiteral['BYTES']r<   r   r   Nr[   r,   r,   r,   r-   r   h     
 r   c                   @  r   )CKDoubleListFieldz,List of floating-point values field wrapper.zLiteral['DOUBLE_LIST']r<   zList[float]r   Nr[   r,   r,   r,   r-   r   p  r   r   c                   @  r   )CKInt64ListFieldz,List of 64-bit integer values field wrapper.zLiteral['INT64_LIST']r<   z	List[int]r   Nr[   r,   r,   r,   r-   r   w  r   r   c                   @  r   )CKAssetIDListFieldz&List of asset ID tokens field wrapper.zLiteral['ASSETID_LIST']r<   zList[CKAssetToken]r   Nr[   r,   r,   r,   r-   r   ~  r   r   c                   @  r   )CKUnknownListFieldz:Fallback list field wrapper for unexpected CloudKit types.zLiteral['UNKNOWN_LIST']r<   zList[JsonValue]r   Nr[   r,   r,   r,   r-   r     r   r   c                   @  r   )CKPassthroughFieldzAGeneric field wrapper for unknown or future CloudKit field types.r   r<   r   r   Nr[   r,   r,   r,   r-   r     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                   @  sR   e Zd ZU dZded< edd Zeddd	Zd
d Ze	dde
d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                 C     t | jddS )z0Retrieve the inner value from the field wrapper.r   Ngetattrr   selfr,   r,   r-   r        zCKFieldOpen.valuer0   rJ   c                 C  r   )z@Retrieve the CloudKit type discriminator from the field wrapper.r<   Nr   r   r,   r,   r-   type_tag  r   zCKFieldOpen.type_tagc                 C  s   | j S )zReturn the inner typed wrapper (e.g., CKTimestampField).
        Public escape hatch; prefer `.value` for most use-cases.
        )r   r   r,   r,   r-   unwrap  s   zCKFieldOpen.unwrapbeforemodec                 C  s   t |tr
|dnd}t |tr|S t |tr#|tv r#t| |S t |tr5d|v r5d|v r5t|S t|r?t||dS d|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tr,   r,   r-   _dispatch_before  s   

zCKFieldOpen._dispatch_beforeN)r0   rJ   )rM   rN   rO   rP   rQ   propertyr   r   r   r   classmethodr   r,   r,   r,   r-   r     s   
 

r   c                      s>   e Zd ZdZdddZ fdd	ZdddZdddZ  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   r0   r   c              
   C  s2   zt | |W S  ty } zt||d}~ww )zARetrieve field value by attribute name instead of dictionary key.N)r   __getitem__KeyErrorAttributeError)r   r   er,   r,   r-   __getattr__*  s   
zCKFields.__getattr__c                   s"   t t  }t|t |  B S )z0List available field names for attribute access.)setsuper__dir__sortedkeys)r   base	__class__r,   r-   r   1  s   zCKFields.__dir__keyc                 C  s,   |  |}|du rdS t|dr| S |S )z=Retrieve the inner typed field wrapper for isinstance checks.Nr   )r   hasattrr   r   r   fr,   r,   r-   	get_field6  s   
zCKFields.get_fieldc                 C  s"   |  |}|du rdS t|ddS )z-Retrieve the decoded value of a field by key.Nr   )r   r   r   r,   r,   r-   	get_value>  s   
zCKFields.get_value)r   r   r0   r   )r   r   )	rM   rN   rO   rP   r   r   r   r   __classcell__r,   r,   r   r-   r     s    

r   c                 C  s2   t | |r| S t | tr|dd |  D S | S )zCValidate a raw field mapping into the requested CK field container.c                 S  s   i | ]
\}}|t |qS r,   )_CK_FIELD_OPEN_ADAPTERvalidate_python).0kvalr,   r,   r-   
<dictcomp>J  s    z)_coerce_field_mapping.<locals>.<dictcomp>)r   r   items)r)   mapping_clsr,   r,   r-   _coerce_field_mappingD  s   

r   c                   @  s  e Zd ZU dZded< ded< eedZded< eddd	e	d
d Z
edd	dd Zee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#d0ed1< dZ$ded2< dZ%ded3< dZ&d4ed5< dS )6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   rZ   
recordTypedefault_factoryr   fieldsr   r   c                 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)   r,   r,   r-   _coerce_fieldsc  s   
zCKRecord._coerce_fieldsafterc                 C  s   | j  D ]?\}}t|tr|dsqt|dr| n|}t|dd}|dkr*q|dkr7t|ddd	u r7q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tagr,   r,   r-   _validate_encrypted_fieldsl  s   z#CKRecord._validate_encrypted_fieldsDict[str, JsonValue]pluginFieldsNrJ   recordChangeTagzOptional[CKAuditInfo]createdmodifiedr   deletedrj   rk   zOptional[CKParent]parentrb   zOptional[CKStableUrl]	stableUrl	shortGUIDzOptional[CKShare]sharepublicPermissionzOptional[List[CKParticipant]]participants
requestersblockeddenyAccessRequestszOptional[CKParticipant]ownercurrentUserParticipantzOptional[CKPCSInfo]
invitedPCSselfAddedPCSr_   zOptional[CKChainProtectionInfo]chainProtectionInfochainParentKeychainPrivateKeyzOptional[SecsOrMillisDateTime]expirationTime)'rM   rN   rO   rP   rQ   r   r   r   r   r   r  r   r
  r   r  r  r  r  r  rk   r  rb   r  r  r  r  r  r  r  r  r  r  r  r  r_   r  r  r   r!  r,   r,   r,   r-   r   T  sF   
 

r   c                   @  rX   )CKWriteParentz4Write-side parent reference embedded under a record.r   rZ   Nr[   r,   r,   r,   r-   r"    r\   r"  c                   @  rv   )CKWriteFieldsz>Field mapping specialized for CloudKit record modify requests.Nrx   r,   r,   r,   r-   r#        r#  c                   @  s   e Zd ZU dZded< ded< eedZded< eedZ	ded	< d
Z
ded< d
Zded< d
Zded< eddded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   rZ   r   r   r#  r   r  r  NrJ   r  zOptional[CKWriteParent]r  rj   rk   r   r   c                 C  r  )z=Convert raw field mapping into typed CKWriteFields container.)r   r#  r  r,   r,   r-   r    s   
zCKWriteRecord._coerce_fields)rM   rN   rO   rP   rQ   r   r#  r   r   r  r  r  rk   r   r   r  r,   r,   r,   r-   r%    s   
 
r%  c                   @  rG   )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   serverErrorCodeNrJ   reasonrZ   )rM   rN   rO   rP   rQ   r(  rZ   r,   r,   r,   r-   r&    s
   
 r&  c                   @  r   )	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   rZ   zLiteral[True]r  Nrj   rk   )rM   rN   rO   rP   rQ   rk   r,   r,   r,   r-   r)    s
   
 r)  c                   @  s<   e Zd ZU dZeed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]]recordsNrJ   continuationMarker	syncToken)
rM   rN   rO   rP   r   listr,  rQ   r-  r.  r,   r,   r,   r-   r*    s   
 r*  c                   @  s0   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)rM   rN   rO   rP   r1  IN_r3  r4  r5  r6  r7  r8  r,   r,   r,   r-   r0    s    r0  c                   @  rv   )_CKFilterValueBasez=Base class for filter value wrappers with type discriminator.Nrx   r,   r,   r,   r-   r:    r$  r:  c                   @  r   )
CKFVStringz'String literal value in a query filter.r   r<   r   r   Nr[   r,   r,   r,   r-   r;    r   r;  c                   @  r   )	CKFVInt64z(Integer literal value in a query filter.r   r<   r   r   Nr[   r,   r,   r,   r-   r<  "  r   r<  c                   @  r   )CKFVStringListz(List of string values in a query filter.r   r<   r   r   Nr[   r,   r,   r,   r-   r=  )  r   r=  c                   @  r   )CKFVReferencez)Record reference value in a query filter.r   r<   r   r   Nr[   r,   r,   r,   r-   r>  0  r   r>  c                   @  r   )CKFVReferenceListz,List of record references in a query filter.r   r<   r   r   Nr[   r,   r,   r,   r-   r?  7  r   r?  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)rM   rN   rO   rP   rQ   rC  r,   r,   r,   r-   rA  J  s   
 rA  c                   @  s*   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   rB  CKFilterValue
fieldValueNr[   r,   r,   r,   r-   rD  T  s
   
 rD  c                   @  r   )	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)rM   rN   rO   rP   rQ   rI  rJ  r,   r,   r,   r-   rH  i  
   
 rH  c                   @  rG   )CKZoneIDReqz8Zone identifier for requests (without redundant fields).r   rI   NrJ   rL   rK   )rM   rN   rO   rP   rQ   rL   rK   r,   r,   r,   r-   rL  w  rR   rL  c                   @  sV   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.
    rH  queryNzOptional[CKZoneIDReq]rk   Optional[List[str]]desiredKeysr   resultsLimitrJ   r-  r   zoneWide)
rM   rN   rO   rP   rQ   rk   rP  rQ  r-  rR  r,   r,   r,   r-   rM    s   
 rM  c                   @  rX   )CKLookupDescriptorz$Specifies a record to fetch by name.r   rZ   Nr[   r,   r,   r,   r-   rS    r\   rS  c                   @  r   )	CKLookupRequestz5Payload for fetching specific records by their names.zList[CKLookupDescriptor]r,  rL  rk   NrO  rP  )rM   rN   rO   rP   rQ   rP  r,   r,   r,   r-   rT    r   rT  c                   @  r@  )CKLookupResponsez6Response containing records fetched by lookup request.r+  r,  NrJ   r.  )rM   rN   rO   rP   rQ   r.  r,   r,   r,   r-   rU    s   
 rU  c                   @  r   )	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.
    rH   rk   NrJ   r.  r   r  )rM   rN   rO   rP   rQ   r.  r  r,   r,   r,   r-   rV    rK  rV  c                   @  $   e Zd ZU dZeedZded< dS )CKZoneListResponsez#Top-level envelope for /zones/list.r   zList[CKZoneListZone]zonesNrM   rN   rO   rP   r   r/  rY  rQ   r,   r,   r,   r-   rX    s   
 rX  c                   @  r@  )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.
    rH   rk   Nr   r  )rM   rN   rO   rP   rQ   r  r,   r,   r,   r-   r[    s   
 r[  c                   @  s<   e Zd ZU dZeed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]rY  Nr   
moreComingrJ   r.  )
rM   rN   rO   rP   r   r/  rY  rQ   r]  r.  r,   r,   r,   r-   r\    s
   
 r\  c                   @  s@   e Zd ZU dZeed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   r+  r,  Nr   r]  r   r.  rH   rk   )	rM   rN   rO   rP   r   r/  r,  rQ   r]  r,   r,   r,   r-   r^    s   
 r^  c                   @  rW  )CKZoneChangesResponsez\
    Top-level envelope for /private/changes/zone (and /shared/changes/zone) responses.
    r   zList[CKZoneChangesZone]rY  NrZ  r,   r,   r,   r-   r_    s   
 r_  c                   @  sJ   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
    rH   rk   NrO  rP  desiredRecordTypesrJ   r.  r   reverse)	rM   rN   rO   rP   rQ   rP  ra  r.  rb  r,   r,   r,   r-   r`    s   
 r`  c                   @  r@  )CKZoneChangesRequestz>Payload for fetching zone changes since a specific sync token.zList[CKZoneChangesZoneReq]rY  Nr   rQ  )rM   rN   rO   rP   rQ   rQ  r,   r,   r,   r-   rc    s   
 rc  c                   @  r   )CKModifyOperationzCSingle record operation in a modify request (create/update/delete).z^Literal['create', 'update', 'forceUpdate', 'replace', 'forceReplace', 'delete', 'forceDelete']operationTyper%  recordNr[   r,   r,   r,   r-   rd    s   
 	rd  c                   @  r   )	CKModifyRequestz(Payload for modifying records in a zone.zList[CKModifyOperation]
operationsrL  rk   Nr   atomic)rM   rN   rO   rP   rQ   ri  r,   r,   r,   r-   rg  +  r   rg  c                   @  s0   e Zd ZU dZeedZded< dZded< dS )CKModifyResponsez:Response containing records after modification operations.r   r+  r,  NrJ   r.  )	rM   rN   rO   rP   r   r/  r,  rQ   r.  r,   r,   r,   r-   rj  3  s   
 rj  N)r/   r   r0   r   )qrP   
__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   rQ   r.   r7   r   rT   r   rE   rF   SecsOrMillisDateTimerH   rS   rY   r]   rd   ri   rm   rp   rs   rw   rz   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   r"  r#  r%  r&  r)  r*  r0  r:  r;  r<  r=  r>  r?  rF  rA  rD  rH  rL  rM  rS  rT  rU  rV  rX  r[  r\  r^  r_  r`  rc  rd  rg  rj  r,   r,   r,   r-   <module>   sJ    0	




			<)[
