Coverage for functions \ flipdare \ generated \ model \ video_history_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
32class VideoHistoryKeys(StrEnum):
33 ID = "id"
34 UPDATED_AT = "updated_at"
35 CREATED_AT = "created_at"
36 VIDEO_ID = "video_id"
37 POSITION = "position"
38 VERSION = "version"
39 PROCESSED = "processed"
40 ERROR_COUNT = "error_count"
43# !! IMPORTANT !!
44# !!
45# !! this should only be used in the database to query.
46# !!
47class VideoHistoryInternalKeys(StrEnum):
48 UPDATED_AT = "updated_at"
49 CREATED_AT = "created_at"
50 VERSION = "VERSION"
51 PROCESSED = "INT_P"
52 ERROR_COUNT = "INT_E"
55class VideoHistoryModel(AppBaseModel):
56 """Represents a user's video watch history, including the video ID and the last watched position."""
58 model_config = ConfigDict(populate_by_name=True, arbitrary_types_allowed=True)
60 id: str | None = Field(None, alias="id")
61 updated_at: FirestoreField = Field(
62 default_factory=cast("Any", lambda: FirestoreTime.server_timestamp())
63 )
64 created_at: FirestoreField = Field(
65 default_factory=cast("Any", lambda: FirestoreTime.server_timestamp())
66 )
67 video_id: str
68 position: int
69 # Version (base internal field)
70 version: int = Field(default=1, alias="VERSION")
71 # Processed (base internal field)
72 processed: bool = Field(default=False, alias="INT_P")
73 # Error Count (base internal field)
74 error_count: int = Field(default=0, alias="INT_E")
76 @classmethod
77 def validate_partial(cls, **data: Unpack[VideoHistoryDict]) -> dict[str, Any]:
78 """
79 Uses Unpack to give you autocomplete and static warnings
80 if you pass an invalid key or type in your code.
82 Returns a dict with Firestore field names (aliases) for use with batch.update().
83 """
84 result: dict[str, Any] = {}
85 for k, v in data.items():
86 if k in cls.__pydantic_fields__:
87 field_info = cls.__pydantic_fields__[k]
88 validated_value = cast(
89 "Any",
90 TypeAdapter(field_info.annotation).validate_python(v),
91 )
92 # Use alias if defined, otherwise use field name
93 output_key = field_info.alias or k
94 result[output_key] = validated_value
95 return result
98VIDEOHISTORY_FIELD_NAMES: list[str] = list(VideoHistoryModel.model_fields.keys())
101class VideoHistoryDict(TypedDict, total=False):
102 id: str | None
103 updated_at: Sentinel | datetime | str
104 created_at: Sentinel | datetime | str
105 video_id: str
106 position: int
107 VERSION: int | None
108 INT_P: bool | None
109 INT_E: int | None