Coverage for functions \ flipdare \ generated \ model \ archived_model.py: 100%

0 statements  

« 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.user.archive_type import ArchiveType 

31 

32 

33class ArchivedKeys(StrEnum): 

34 ID = "id" 

35 CREATED_AT = "created_at" 

36 UPDATED_AT = "updated_at" 

37 ARCHIVE_TYPE = "archive_type" 

38 OBJ_ID = "obj_id" 

39 VERSION = "version" 

40 PROCESSED = "processed" 

41 ERROR_COUNT = "error_count" 

42 

43 

44# !! IMPORTANT !! 

45# !! 

46# !! this should only be used in the database to query. 

47# !! 

48class ArchivedInternalKeys(StrEnum): 

49 CREATED_AT = "created_at" 

50 UPDATED_AT = "updated_at" 

51 VERSION = "VERSION" 

52 PROCESSED = "INT_P" 

53 ERROR_COUNT = "INT_E" 

54 

55 

56class ArchivedModel(AppBaseModel): 

57 """Represents an archived object in the system""" 

58 

59 model_config = ConfigDict(populate_by_name=True, arbitrary_types_allowed=True) 

60 

61 id: str | None = Field(None, alias="id") 

62 created_at: FirestoreField = Field( 

63 default_factory=cast("Any", lambda: FirestoreTime.server_timestamp()) 

64 ) 

65 updated_at: FirestoreField = Field( 

66 default_factory=cast("Any", lambda: FirestoreTime.server_timestamp()) 

67 ) 

68 archive_type: ArchiveType 

69 obj_id: str 

70 # Version (base internal field) 

71 version: int = Field(default=1, alias="VERSION") 

72 # Processed (base internal field) 

73 processed: bool = Field(default=False, alias="INT_P") 

74 # Error Count (base internal field) 

75 error_count: int = Field(default=0, alias="INT_E") 

76 

77 @classmethod 

78 def validate_partial(cls, **data: Unpack[ArchivedDict]) -> dict[str, Any]: 

79 """ 

80 Uses Unpack to give you autocomplete and static warnings 

81 if you pass an invalid key or type in your code. 

82 

83 Returns a dict with Firestore field names (aliases) for use with batch.update(). 

84 """ 

85 result: dict[str, Any] = {} 

86 for k, v in data.items(): 

87 if k in cls.__pydantic_fields__: 

88 field_info = cls.__pydantic_fields__[k] 

89 validated_value = cast( 

90 "Any", 

91 TypeAdapter(field_info.annotation).validate_python(v), 

92 ) 

93 # Use alias if defined, otherwise use field name 

94 output_key = field_info.alias or k 

95 result[output_key] = validated_value 

96 return result 

97 

98 

99ARCHIVED_FIELD_NAMES: list[str] = list(ArchivedModel.model_fields.keys()) 

100 

101 

102class ArchivedDict(TypedDict, total=False): 

103 id: str | None 

104 created_at: Sentinel | datetime | str 

105 updated_at: Sentinel | datetime | str 

106 archive_type: ArchiveType 

107 obj_id: str 

108 VERSION: int | None 

109 INT_P: bool | None 

110 INT_E: int | None