# coding: utf-8

"""
    Civitai Orchestration Consumer API

    No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)

    The version of the OpenAPI document: v1
    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, StrictFloat, StrictInt, StrictStr
from typing import Any, ClassVar, Dict, List, Optional, Union
from civitai_py.models.image_job_network_params import ImageJobNetworkParams
from civitai_py.models.time_span import TimeSpan
from typing import Optional, Set
from typing_extensions import Self


class PinModelJob(BaseModel):
    """
    PinModelJob
    """  # noqa: E501
    assets: Optional[Dict[str, ImageJobNetworkParams]] = None
    type: Optional[StrictStr] = None
    id: Optional[StrictStr] = Field(default=None, description="A unique id for this job")
    created_at: Optional[datetime] = Field(
        default=None, description="The date when this job got created", alias="createdAt")
    expire_at: Optional[datetime] = Field(
        default=None, description="The date for when this job was set to expire", alias="expireAt")
    webhook: Optional[StrictStr] = Field(
        default=None, description="A webhook to be invoked when the job receives a status update")
    properties: Optional[Dict[str, Dict[str, Any]]] = Field(
        default=None, description="A set of user defined properties that can be used to index and partition this job")
    cost: Optional[Union[StrictFloat, StrictInt]] = Field(
        default=None, description="Get a cost estimate for this job")
    max_retry_attempt: Optional[StrictInt] = Field(
        default=None, description="The max number of retries before we give up", alias="maxRetryAttempt")
    dependencies: Optional[List[StrictStr]] = Field(
        default=None, description="Get or set a list of dependencies that this job has")
    issued_by: Optional[StrictStr] = Field(
        default=None, description="Get or set the name of the consumer that issued this job", alias="issuedBy")
    claim_duration: Optional[TimeSpan] = Field(default=None, alias="claimDuration")
    __properties: ClassVar[List[str]] = ["id", "createdAt", "expireAt", "webhook", "properties",
                                         "type", "cost", "maxRetryAttempt", "dependencies", "issuedBy", "claimDuration"]

    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 PinModelJob 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.
        * OpenAPI `readOnly` fields are excluded.
        * OpenAPI `readOnly` fields are excluded.
        """
        excluded_fields: Set[str] = set([
            "type",
            "cost",
        ])

        _dict = self.model_dump(
            by_alias=True,
            exclude=excluded_fields,
            exclude_none=True,
        )
        # override the default output from pydantic by calling `to_dict()` of claim_duration
        if self.claim_duration:
            _dict['claimDuration'] = self.claim_duration.to_dict()
        # set to None if id (nullable) is None
        # and model_fields_set contains the field
        if self.id is None and "id" in self.model_fields_set:
            _dict['id'] = None

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

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

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

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

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

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

        return _dict

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

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

        _obj = cls.model_validate({
            "id": obj.get("id"),
            "createdAt": obj.get("createdAt"),
            "expireAt": obj.get("expireAt"),
            "webhook": obj.get("webhook"),
            "properties": obj.get("properties"),
            "type": obj.get("type"),
            "cost": obj.get("cost"),
            "maxRetryAttempt": obj.get("maxRetryAttempt"),
            "dependencies": obj.get("dependencies"),
            "issuedBy": obj.get("issuedBy"),
            "claimDuration": TimeSpan.from_dict(obj["claimDuration"]) if obj.get("claimDuration") is not None else None
        })
        return _obj
