# coding: utf-8

"""
    Artifact Keeper API

    Enterprise artifact registry supporting 45+ package formats.

    The version of the OpenAPI document: 1.0.0-rc.3
    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, StrictInt, StrictStr
from typing import Any, ClassVar, Dict, List, Optional
from artifact_keeper_client.models.build_module import BuildModule
from typing import Optional, Set
from typing_extensions import Self

class BuildResponse(BaseModel):
    """
    BuildResponse
    """ # noqa: E501
    agent: Optional[StrictStr] = None
    artifact_count: Optional[StrictInt] = None
    created_at: datetime
    duration_ms: Optional[StrictInt] = None
    finished_at: Optional[datetime] = None
    id: StrictStr
    metadata: Optional[Dict[str, Any]] = None
    modules: Optional[List[BuildModule]] = None
    name: StrictStr
    number: StrictInt
    started_at: Optional[datetime] = None
    status: StrictStr
    updated_at: datetime
    vcs_branch: Optional[StrictStr] = None
    vcs_message: Optional[StrictStr] = None
    vcs_revision: Optional[StrictStr] = None
    vcs_url: Optional[StrictStr] = None
    __properties: ClassVar[List[str]] = ["agent", "artifact_count", "created_at", "duration_ms", "finished_at", "id", "metadata", "modules", "name", "number", "started_at", "status", "updated_at", "vcs_branch", "vcs_message", "vcs_revision", "vcs_url"]

    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 BuildResponse 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 each item in modules (list)
        _items = []
        if self.modules:
            for _item_modules in self.modules:
                if _item_modules:
                    _items.append(_item_modules.to_dict())
            _dict['modules'] = _items
        # set to None if agent (nullable) is None
        # and model_fields_set contains the field
        if self.agent is None and "agent" in self.model_fields_set:
            _dict['agent'] = None

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

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

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

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

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

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

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

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

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

        return _dict

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

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

        _obj = cls.model_validate({
            "agent": obj.get("agent"),
            "artifact_count": obj.get("artifact_count"),
            "created_at": obj.get("created_at"),
            "duration_ms": obj.get("duration_ms"),
            "finished_at": obj.get("finished_at"),
            "id": obj.get("id"),
            "metadata": obj.get("metadata"),
            "modules": [BuildModule.from_dict(_item) for _item in obj["modules"]] if obj.get("modules") is not None else None,
            "name": obj.get("name"),
            "number": obj.get("number"),
            "started_at": obj.get("started_at"),
            "status": obj.get("status"),
            "updated_at": obj.get("updated_at"),
            "vcs_branch": obj.get("vcs_branch"),
            "vcs_message": obj.get("vcs_message"),
            "vcs_revision": obj.get("vcs_revision"),
            "vcs_url": obj.get("vcs_url")
        })
        return _obj


