# coding: utf-8

"""
    Mender API

    Combined API specification for the features of the different Mender backend services, suitable for code generation applications 

    The version of the OpenAPI document: 1
    Contact: support@mender.io
    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, StrictInt, StrictStr
from typing import Any, ClassVar, Dict, List, Optional
from mender_client.models.artifact_info import ArtifactInfo
from mender_client.models.update import Update
from typing import Optional, Set
from typing_extensions import Self

class ArtifactV1(BaseModel):
    """
    Detailed artifact.
    """ # noqa: E501
    id: StrictStr
    name: StrictStr
    description: Optional[StrictStr] = None
    device_types_compatible: List[StrictStr] = Field(description="An array of compatible device types.")
    info: Optional[ArtifactInfo] = None
    signed: Optional[StrictBool] = Field(default=None, description="Idicates if artifact is signed or not.")
    updates: Optional[List[Update]] = None
    artifact_provides: Optional[Dict[str, StrictStr]] = Field(default=None, description="List of Artifact provides.  Map of key/value pairs, where both keys and values are strings. ")
    artifact_depends: Optional[Dict[str, List[StrictStr]]] = Field(default=None, description="List of Artifact depends.  Map of key/value pairs, where keys are strings and values are lists of strings. ")
    clears_artifact_provides: Optional[List[StrictStr]] = Field(default=None, description="List of Clear Artifact provides.")
    size: Optional[StrictInt] = Field(default=None, description="Artifact total size in bytes - the size of the actual file that will be transferred to the device (compressed). ")
    modified: datetime = Field(description="Represents creation / last edition of any of the artifact properties. ")
    __properties: ClassVar[List[str]] = ["id", "name", "description", "device_types_compatible", "info", "signed", "updates", "artifact_provides", "artifact_depends", "clears_artifact_provides", "size", "modified"]

    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 ArtifactV1 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,
        )
        # override the default output from pydantic by calling `to_dict()` of info
        if self.info:
            _dict['info'] = self.info.to_dict()
        # override the default output from pydantic by calling `to_dict()` of each item in updates (list)
        _items = []
        if self.updates:
            for _item_updates in self.updates:
                if _item_updates:
                    _items.append(_item_updates.to_dict())
            _dict['updates'] = _items
        return _dict

    @classmethod
    def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
        """Create an instance of ArtifactV1 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"),
            "name": obj.get("name"),
            "description": obj.get("description"),
            "device_types_compatible": obj.get("device_types_compatible"),
            "info": ArtifactInfo.from_dict(obj["info"]) if obj.get("info") is not None else None,
            "signed": obj.get("signed"),
            "updates": [Update.from_dict(_item) for _item in obj["updates"]] if obj.get("updates") is not None else None,
            "artifact_provides": obj.get("artifact_provides"),
            "artifact_depends": obj.get("artifact_depends"),
            "clears_artifact_provides": obj.get("clears_artifact_provides"),
            "size": obj.get("size"),
            "modified": obj.get("modified")
        })
        return _obj


