Coverage for functions \ flipdare \ generated \ model \ payment \ pledge_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.stripe.stripe_currency_code import StripeCurrencyCode
31from flipdare.generated.shared.model.pledge_status import PledgeStatus
32from flipdare.generated.shared.model.dare.vote_result import VoteResult
33from flipdare.generated.model.payment.payment_model import PaymentModel, PaymentDict
36class PledgeKeys(StrEnum):
37 ID = "id"
38 UPDATED_AT = "updated_at"
39 CREATED_AT = "created_at"
40 FROM_UID = "from_uid"
41 DARE_ID = "dare_id"
42 SLUG_CODE = "slug_code"
43 TO_UID = "to_uid"
44 GID = "gid"
45 AMOUNT = "amount"
46 CURRENCY_CODE = "currency_code"
47 STATUS = "status"
48 VOTE_RESULT = "vote_result"
49 PAYMENT = "payment"
50 PAYMENT_EVENT_CT = "payment_event_ct"
51 VERSION = "version"
52 PROCESSED = "processed"
53 ERROR_COUNT = "error_count"
54 ADDITIONAL_INFO_COUNT = "additional_info_count"
55 INVALID_PAYMENT = "invalid_payment"
56 NOTIFIED_PROCESSING = "notified_processing"
57 NOTIFIED_PROCESSED = "notified_processed"
58 EVIDENCE_SENT = "evidence_sent"
61# !! IMPORTANT !!
62# !!
63# !! this should only be used in the database to query.
64# !!
65class PledgeInternalKeys(StrEnum):
66 UPDATED_AT = "updated_at"
67 CREATED_AT = "created_at"
68 VERSION = "VERSION"
69 PROCESSED = "INT_P"
70 ERROR_COUNT = "INT_E"
71 ADDITIONAL_INFO_COUNT = "INT_A_I_C"
72 INVALID_PAYMENT = "INT_I_P"
73 NOTIFIED_PROCESSING = "INT_N_PRO_ING"
74 NOTIFIED_PROCESSED = "INT_N_PRO_CED"
75 EVIDENCE_SENT = "INT_E_S"
78class PledgeModel(AppBaseModel):
79 """Represents a pledge made by a user for a dare"""
81 model_config = ConfigDict(populate_by_name=True, arbitrary_types_allowed=True)
83 id: str | None = Field(None, alias="id")
84 updated_at: FirestoreField = Field(
85 default_factory=cast("Any", lambda: FirestoreTime.server_timestamp())
86 )
87 created_at: FirestoreField = Field(
88 default_factory=cast("Any", lambda: FirestoreTime.server_timestamp())
89 )
90 # References to depdendent models, such as user and dare.
91 from_uid: str
92 dare_id: str
93 slug_code: str
94 to_uid: str | None = None
95 gid: str | None = None
96 # Initial charge information.
97 amount: int
98 currency_code: StripeCurrencyCode
99 # statuses of the pledge.
100 status: PledgeStatus = Field(default=PledgeStatus.UNDECIDED)
101 vote_result: VoteResult | None = None
102 # this needs to be created on the server, so it's not required when the because its created on the gui.
103 payment: PaymentModel | None = None
104 # The number of payment events that have occurred for this pledge.
105 payment_event_ct: int = Field(default=0)
106 # Version (base internal field)
107 version: int = Field(default=1, alias="VERSION")
108 # Processed (base internal field)
109 processed: bool = Field(default=False, alias="INT_P")
110 # Error Count (base internal field)
111 error_count: int = Field(default=0, alias="INT_E")
112 # Additional Info Count (internal field for counting the number of times additional info has been requested for this pledge)
113 additional_info_count: int = Field(default=0, alias="INT_A_I_C")
114 # Invalid Payment (internal field)
115 invalid_payment: bool = Field(default=False, alias="INT_I_P")
116 # Notified Processing (internal field)
117 notified_processing: bool = Field(default=False, alias="INT_N_PRO_ING")
118 # Notified Processed (internal field)
119 notified_processed: bool = Field(default=False, alias="INT_N_PRO_CED")
120 # Evidence Sent for a dispute/chargeback (internal field)
121 evidence_sent: bool = Field(default=False, alias="INT_E_S")
123 @classmethod
124 def validate_partial(cls, **data: Unpack[PledgeDict]) -> dict[str, Any]:
125 """
126 Uses Unpack to give you autocomplete and static warnings
127 if you pass an invalid key or type in your code.
129 Returns a dict with Firestore field names (aliases) for use with batch.update().
130 """
131 result: dict[str, Any] = {}
132 for k, v in data.items():
133 if k in cls.__pydantic_fields__:
134 field_info = cls.__pydantic_fields__[k]
135 validated_value = cast(
136 "Any",
137 TypeAdapter(field_info.annotation).validate_python(v),
138 )
139 # Use alias if defined, otherwise use field name
140 output_key = field_info.alias or k
141 result[output_key] = validated_value
142 return result
145PLEDGE_FIELD_NAMES: list[str] = list(PledgeModel.model_fields.keys())
148class PledgeDict(TypedDict, total=False):
149 id: str | None
150 updated_at: Sentinel | datetime | str
151 created_at: Sentinel | datetime | str
152 from_uid: str
153 dare_id: str
154 slug_code: str
155 to_uid: str | None
156 gid: str | None
157 amount: int
158 currency_code: StripeCurrencyCode
159 status: PledgeStatus | None
160 vote_result: VoteResult | None
161 payment: PaymentDict | None
162 payment_event_ct: int | None
163 VERSION: int | None
164 INT_P: bool | None
165 INT_E: int | None
166 INT_A_I_C: int | None
167 INT_I_P: bool | None
168 INT_N_PRO_ING: bool | None
169 INT_N_PRO_CED: bool | None
170 INT_E_S: bool | None