# coding: utf-8

"""
    ICAT+ API

    ICAT+ RESTful API with Swagger

    The version of the OpenAPI document: 1.0.0
    Contact: demariaa@esrf.fr
    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 pydantic import BaseModel, ConfigDict, Field, StrictStr
from typing import Any, ClassVar, Dict, List, Optional
from icat_plus_client.models.ewoks_session_id_jobs_put_request_step import EwoksSessionIdJobsPutRequestStep
from icat_plus_client.models.job_investigations_inner import JobInvestigationsInner
from typing import Optional, Set
from typing_extensions import Self

class Job(BaseModel):
    """
    a reprocessing job
    """ # noqa: E501
    id: Optional[StrictStr] = Field(default=None, alias="_id")
    dataset_ids: Optional[List[StrictStr]] = Field(default=None, alias="datasetIds")
    sample_ids: Optional[List[StrictStr]] = Field(default=None, alias="sampleIds")
    user_names: Optional[List[StrictStr]] = Field(default=None, alias="userNames")
    investigations: Optional[List[JobInvestigationsInner]] = None
    identifier: Optional[StrictStr] = None
    input: Optional[Dict[str, Any]] = None
    logs: Optional[List[Dict[str, Any]]] = None
    status: Optional[StrictStr] = None
    statuses: Optional[List[StrictStr]] = None
    steps: Optional[List[EwoksSessionIdJobsPutRequestStep]] = None
    job_id: Optional[StrictStr] = Field(default=None, alias="jobId")
    workflow: Optional[Dict[str, Any]] = None
    created_at: Optional[StrictStr] = Field(default=None, alias="createdAt")
    updated_at: Optional[StrictStr] = Field(default=None, alias="updatedAt")
    __properties: ClassVar[List[str]] = ["_id", "datasetIds", "sampleIds", "userNames", "investigations", "identifier", "input", "logs", "status", "statuses", "steps", "jobId", "workflow", "createdAt", "updatedAt"]

    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 Job 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 investigations (list)
        _items = []
        if self.investigations:
            for _item_investigations in self.investigations:
                if _item_investigations:
                    _items.append(_item_investigations.to_dict())
            _dict['investigations'] = _items
        # override the default output from pydantic by calling `to_dict()` of each item in steps (list)
        _items = []
        if self.steps:
            for _item_steps in self.steps:
                if _item_steps:
                    _items.append(_item_steps.to_dict())
            _dict['steps'] = _items
        return _dict

    @classmethod
    def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
        """Create an instance of Job 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"),
            "datasetIds": obj.get("datasetIds"),
            "sampleIds": obj.get("sampleIds"),
            "userNames": obj.get("userNames"),
            "investigations": [JobInvestigationsInner.from_dict(_item) for _item in obj["investigations"]] if obj.get("investigations") is not None else None,
            "identifier": obj.get("identifier"),
            "input": obj.get("input"),
            "logs": obj.get("logs"),
            "status": obj.get("status"),
            "statuses": obj.get("statuses"),
            "steps": [EwoksSessionIdJobsPutRequestStep.from_dict(_item) for _item in obj["steps"]] if obj.get("steps") is not None else None,
            "jobId": obj.get("jobId"),
            "workflow": obj.get("workflow"),
            "createdAt": obj.get("createdAt"),
            "updatedAt": obj.get("updatedAt")
        })
        return _obj


