Coverage for functions \ flipdare \ generated \ model \ pledge_stats_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.model.pledge_stats_value_model import (
32 PledgeStatsValueModel,
33 PledgeStatsValueDict,
34)
37class PledgeStatsKeys(StrEnum):
38 UPDATED_AT = "updated_at"
39 CREATED_AT = "created_at"
40 BASE_CURRENCY_CODE = "base_currency_code"
41 PLEDGE_MIN_CENTS = "pledge_min_cents"
42 PLEDGE_MIN_CENTS_USD = "pledge_min_cents_usd"
43 PENDING = "pending"
44 REJECTED = "rejected"
45 ACCEPTED = "accepted"
46 EARNED = "earned"
47 CANCELLED = "cancelled"
48 DISPUTED = "disputed"
49 REFUNDED = "refunded"
50 ERROR = "error"
53# !! IMPORTANT !!
54# !!
55# !! this should only be used in the database to query.
56# !!
57class PledgeStatsInternalKeys(StrEnum):
58 UPDATED_AT = "updated_at"
59 CREATED_AT = "created_at"
62class PledgeStatsModel(AppBaseModel):
63 """Represents aggregated stats for pledges on a dare."""
65 model_config = ConfigDict(populate_by_name=True, arbitrary_types_allowed=True)
67 updated_at: FirestoreField = Field(
68 default_factory=cast("Any", lambda: FirestoreTime.server_timestamp())
69 )
70 created_at: FirestoreField = Field(
71 default_factory=cast("Any", lambda: FirestoreTime.server_timestamp())
72 )
73 base_currency_code: StripeCurrencyCode = Field(default=StripeCurrencyCode.USD)
74 pledge_min_cents: int = Field(default=100)
75 pledge_min_cents_usd: int = Field(default=100)
76 pending: PledgeStatsValueModel = Field(default_factory=lambda: PledgeStatsValueModel())
77 rejected: PledgeStatsValueModel = Field(default_factory=lambda: PledgeStatsValueModel())
78 accepted: PledgeStatsValueModel = Field(default_factory=lambda: PledgeStatsValueModel())
79 earned: PledgeStatsValueModel = Field(default_factory=lambda: PledgeStatsValueModel())
80 cancelled: PledgeStatsValueModel = Field(default_factory=lambda: PledgeStatsValueModel())
81 disputed: PledgeStatsValueModel = Field(default_factory=lambda: PledgeStatsValueModel())
82 refunded: PledgeStatsValueModel = Field(default_factory=lambda: PledgeStatsValueModel())
83 error: PledgeStatsValueModel = Field(default_factory=lambda: PledgeStatsValueModel())
85 @classmethod
86 def validate_partial(cls, **data: Unpack[PledgeStatsDict]) -> dict[str, Any]:
87 """
88 Uses Unpack to give you autocomplete and static warnings
89 if you pass an invalid key or type in your code.
91 Returns a dict with Firestore field names (aliases) for use with batch.update().
92 """
93 result: dict[str, Any] = {}
94 for k, v in data.items():
95 if k in cls.__pydantic_fields__:
96 field_info = cls.__pydantic_fields__[k]
97 validated_value = cast(
98 "Any",
99 TypeAdapter(field_info.annotation).validate_python(v),
100 )
101 # Use alias if defined, otherwise use field name
102 output_key = field_info.alias or k
103 result[output_key] = validated_value
104 return result
106 # ---- Convenience predicates -----------------------------------------
107 @property
108 def total_count(self) -> int:
109 """Returns the total count of all pledge stats."""
110 return (
111 self.pending.count
112 + self.rejected.count
113 + self.accepted.count
114 + self.earned.count
115 + self.cancelled.count
116 + self.disputed.count
117 + self.refunded.count
118 + self.error.count
119 )
122PLEDGESTATS_FIELD_NAMES: list[str] = list(PledgeStatsModel.model_fields.keys())
125class PledgeStatsDict(TypedDict, total=False):
126 updated_at: Sentinel | datetime | str
127 created_at: Sentinel | datetime | str
128 base_currency_code: StripeCurrencyCode | None
129 pledge_min_cents: int | None
130 pledge_min_cents_usd: int | None
131 pending: PledgeStatsValueDict
132 rejected: PledgeStatsValueDict
133 accepted: PledgeStatsValueDict
134 earned: PledgeStatsValueDict
135 cancelled: PledgeStatsValueDict
136 disputed: PledgeStatsValueDict
137 refunded: PledgeStatsValueDict
138 error: PledgeStatsValueDict