Coverage for functions \ flipdare \ generated \ model \ friend_model.py: 100%
0 statements
« prev ^ index » next coverage.py v7.13.0, created at 2026-05-08 12:22 +1000
« prev ^ index » next coverage.py v7.13.0, created at 2026-05-08 12:22 +1000
1#!/usr/bin/env python
2#
3# Copyright (c) 2026 Flipdare Pty Ltd. All rights reserved.
4#
5# This file is part of Flipdare's proprietary software and contains
6# confidential and copyrighted material. Unauthorised copying,
7# modification, distribution, or use of this file is strictly
8# prohibited without prior written permission from Flipdare Pty Ltd.
9#
10# This software includes third-party components licensed under MIT,
11# BSD, and Apache 2.0 licences. See THIRD_PARTY_NOTICES for details.
12#
13# NOTE: THIS FILE IS AUTO GENERATED. DO NOT EDIT.
14#
15# Generated by codegen_models.py
16#
17# Modify 'codegen_models.py'
18# and re-run the script above to update.
19#
20# pragma: no cover
21from __future__ import annotations
22from datetime import datetime
23from google.cloud.firestore_v1.transforms import Sentinel
24from flipdare.core.firestore_field import FirestoreField
25from flipdare.util.time_util import FirestoreTime
26from typing import Any, TypedDict, cast, Unpack
27from enum import StrEnum
28from pydantic import Field, ConfigDict, TypeAdapter
29from flipdare.firestore.core.app_base_model import AppBaseModel
30from flipdare.generated.shared.model.friend_type import FriendType
31from flipdare.generated.shared.model.user.request_status import RequestStatus
34class FriendKeys(StrEnum):
35 ID = "id"
36 CREATED_AT = "created_at"
37 UPDATED_AT = "updated_at"
38 FRIEND_TYPE = "friend_type"
39 STATUS = "status"
40 FROM_UID = "from_uid"
41 TO_UID = "to_uid"
42 VERSION = "version"
43 PROCESSED = "processed"
44 ERROR_COUNT = "error_count"
45 CREATED = "created"
46 CONTEXT_CREATED = "context_created"
47 EMAIL_SENT = "email_sent"
48 NOTIFICATION_SENT = "notification_sent"
49 RECIPROCAL_FRIEND_CREATED = "reciprocal_friend_created"
50 SEARCH_INDEXED = "search_indexed"
53# !! IMPORTANT !!
54# !!
55# !! this should only be used in the database to query.
56# !!
57class FriendInternalKeys(StrEnum):
58 CREATED_AT = "created_at"
59 UPDATED_AT = "updated_at"
60 VERSION = "VERSION"
61 PROCESSED = "INT_P"
62 ERROR_COUNT = "INT_E"
63 CREATED = "INT_F_C"
64 CONTEXT_CREATED = "INT_F_CC"
65 EMAIL_SENT = "INT_F_ES"
66 NOTIFICATION_SENT = "INT_F_NS"
67 RECIPROCAL_FRIEND_CREATED = "INT_F_RF"
68 SEARCH_INDEXED = "INT_F_SI"
71class FriendModel(AppBaseModel):
72 """Represents a friendship or friend request between two users in the system."""
74 model_config = ConfigDict(populate_by_name=True, arbitrary_types_allowed=True)
76 id: str | None = Field(None, alias="id")
77 created_at: FirestoreField = Field(
78 default_factory=cast("Any", lambda: FirestoreTime.server_timestamp())
79 )
80 updated_at: FirestoreField = Field(
81 default_factory=cast("Any", lambda: FirestoreTime.server_timestamp())
82 )
83 friend_type: FriendType = Field(default=FriendType.USER)
84 status: RequestStatus = Field(default=RequestStatus.PENDING)
85 from_uid: str
86 to_uid: str
87 # Version (base internal field)
88 version: int = Field(default=1, alias="VERSION")
89 # Processed (base internal field)
90 processed: bool = Field(default=False, alias="INT_P")
91 # Error Count (base internal field)
92 error_count: int = Field(default=0, alias="INT_E")
93 # Created (internal field)
94 created: bool = Field(default=False, alias="INT_F_C")
95 # Context Created (internal field)
96 context_created: bool = Field(default=False, alias="INT_F_CC")
97 # Email Sent (internal field)
98 email_sent: bool = Field(default=False, alias="INT_F_ES")
99 # Notification Sent (internal field)
100 notification_sent: bool = Field(default=False, alias="INT_F_NS")
101 # Reciprocal Friend Created (internal field)
102 reciprocal_friend_created: bool = Field(default=False, alias="INT_F_RF")
103 # Search Indexed (internal field)
104 search_indexed: bool = Field(default=False, alias="INT_F_SI")
106 @classmethod
107 def validate_partial(cls, **data: Unpack[FriendDict]) -> dict[str, Any]:
108 """
109 Uses Unpack to give you autocomplete and static warnings
110 if you pass an invalid key or type in your code.
112 Returns a dict with Firestore field names (aliases) for use with batch.update().
113 """
114 result: dict[str, Any] = {}
115 for k, v in data.items():
116 if k in cls.__pydantic_fields__:
117 field_info = cls.__pydantic_fields__[k]
118 validated_value = cast(
119 "Any",
120 TypeAdapter(field_info.annotation).validate_python(v),
121 )
122 # Use alias if defined, otherwise use field name
123 output_key = field_info.alias or k
124 result[output_key] = validated_value
125 return result
128FRIEND_FIELD_NAMES: list[str] = list(FriendModel.model_fields.keys())
131class FriendDict(TypedDict, total=False):
132 id: str | None
133 created_at: Sentinel | datetime | str
134 updated_at: Sentinel | datetime | str
135 friend_type: FriendType | None
136 status: RequestStatus | None
137 from_uid: str
138 to_uid: str
139 VERSION: int | None
140 INT_P: bool | None
141 INT_E: int | None
142 INT_F_C: bool | None
143 INT_F_CC: bool | None
144 INT_F_ES: bool | None
145 INT_F_NS: bool | None
146 INT_F_RF: bool | None
147 INT_F_SI: bool | None