# coding: utf-8

"""
Immich

Immich API

The version of the OpenAPI document: 2.4.1
Generated by OpenAPI Generator (https://openapi-generator.tech)

Do not edit the class manually.
"""  # noqa: E501

from __future__ import annotations
import pprint
import re  # noqa: F401
import json

from datetime import datetime
from pydantic import BaseModel, ConfigDict, Field, StrictBool, StrictStr
from typing import Any, ClassVar, Dict, List, Optional
from immich.client.models.asset_type_enum import AssetTypeEnum
from immich.client.models.asset_visibility import AssetVisibility
from typing import Set
from typing_extensions import Self


class SyncAssetV1(BaseModel):
    """
    SyncAssetV1
    """  # noqa: E501

    checksum: StrictStr
    deleted_at: Optional[datetime] = Field(alias="deletedAt")
    duration: Optional[StrictStr]
    file_created_at: Optional[datetime] = Field(alias="fileCreatedAt")
    file_modified_at: Optional[datetime] = Field(alias="fileModifiedAt")
    id: StrictStr
    is_favorite: StrictBool = Field(alias="isFavorite")
    library_id: Optional[StrictStr] = Field(alias="libraryId")
    live_photo_video_id: Optional[StrictStr] = Field(alias="livePhotoVideoId")
    local_date_time: Optional[datetime] = Field(alias="localDateTime")
    original_file_name: StrictStr = Field(alias="originalFileName")
    owner_id: StrictStr = Field(alias="ownerId")
    stack_id: Optional[StrictStr] = Field(alias="stackId")
    thumbhash: Optional[StrictStr]
    type: AssetTypeEnum
    visibility: AssetVisibility
    __properties: ClassVar[List[str]] = [
        "checksum",
        "deletedAt",
        "duration",
        "fileCreatedAt",
        "fileModifiedAt",
        "id",
        "isFavorite",
        "libraryId",
        "livePhotoVideoId",
        "localDateTime",
        "originalFileName",
        "ownerId",
        "stackId",
        "thumbhash",
        "type",
        "visibility",
    ]

    model_config = ConfigDict(
        populate_by_name=True,
        validate_assignment=True,
        protected_namespaces=(),
    )

    def to_str(self) -> str:
        """Returns the string representation of the model using alias"""
        return pprint.pformat(self.model_dump(by_alias=True))

    def to_json(self) -> str:
        """Returns the JSON representation of the model using alias"""
        # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead
        return json.dumps(self.to_dict())

    @classmethod
    def from_json(cls, json_str: str) -> Optional[Self]:
        """Create an instance of SyncAssetV1 from a JSON string"""
        return cls.from_dict(json.loads(json_str))

    def to_dict(self) -> Dict[str, Any]:
        """Return the dictionary representation of the model using alias.

        This has the following differences from calling pydantic's
        `self.model_dump(by_alias=True)`:

        * `None` is only added to the output dict for nullable fields that
          were set at model initialization. Other fields with value `None`
          are ignored.
        """
        excluded_fields: Set[str] = set([])

        _dict = self.model_dump(
            by_alias=True,
            exclude=excluded_fields,
            exclude_none=True,
        )
        # set to None if deleted_at (nullable) is None
        # and model_fields_set contains the field
        if self.deleted_at is None and "deleted_at" in self.model_fields_set:
            _dict["deletedAt"] = None

        # set to None if duration (nullable) is None
        # and model_fields_set contains the field
        if self.duration is None and "duration" in self.model_fields_set:
            _dict["duration"] = None

        # set to None if file_created_at (nullable) is None
        # and model_fields_set contains the field
        if self.file_created_at is None and "file_created_at" in self.model_fields_set:
            _dict["fileCreatedAt"] = None

        # set to None if file_modified_at (nullable) is None
        # and model_fields_set contains the field
        if (
            self.file_modified_at is None
            and "file_modified_at" in self.model_fields_set
        ):
            _dict["fileModifiedAt"] = None

        # set to None if library_id (nullable) is None
        # and model_fields_set contains the field
        if self.library_id is None and "library_id" in self.model_fields_set:
            _dict["libraryId"] = None

        # set to None if live_photo_video_id (nullable) is None
        # and model_fields_set contains the field
        if (
            self.live_photo_video_id is None
            and "live_photo_video_id" in self.model_fields_set
        ):
            _dict["livePhotoVideoId"] = None

        # set to None if local_date_time (nullable) is None
        # and model_fields_set contains the field
        if self.local_date_time is None and "local_date_time" in self.model_fields_set:
            _dict["localDateTime"] = None

        # set to None if stack_id (nullable) is None
        # and model_fields_set contains the field
        if self.stack_id is None and "stack_id" in self.model_fields_set:
            _dict["stackId"] = None

        # set to None if thumbhash (nullable) is None
        # and model_fields_set contains the field
        if self.thumbhash is None and "thumbhash" in self.model_fields_set:
            _dict["thumbhash"] = None

        return _dict

    @classmethod
    def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
        """Create an instance of SyncAssetV1 from a dict"""
        if obj is None:
            return None

        if not isinstance(obj, dict):
            return cls.model_validate(obj)

        _obj = cls.model_validate(
            {
                "checksum": obj.get("checksum"),
                "deletedAt": obj.get("deletedAt"),
                "duration": obj.get("duration"),
                "fileCreatedAt": obj.get("fileCreatedAt"),
                "fileModifiedAt": obj.get("fileModifiedAt"),
                "id": obj.get("id"),
                "isFavorite": obj.get("isFavorite"),
                "libraryId": obj.get("libraryId"),
                "livePhotoVideoId": obj.get("livePhotoVideoId"),
                "localDateTime": obj.get("localDateTime"),
                "originalFileName": obj.get("originalFileName"),
                "ownerId": obj.get("ownerId"),
                "stackId": obj.get("stackId"),
                "thumbhash": obj.get("thumbhash"),
                "type": obj.get("type"),
                "visibility": obj.get("visibility"),
            }
        )
        return _obj
