# coding: utf-8

"""
    LEIA RESTful API for AI

    Leia API  # noqa: E501

    The version of the OpenAPI document: 1.0.0
    Contact: contact@leia.io
    Generated by: https://openapi-generator.tech
"""


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

from datetime import datetime
from typing import List, Optional
from pydantic import BaseModel, StrictStr
from leiaapi.generated.models.job_result import JobResult
from leiaapi.generated.models.result_types import ResultTypes
from leiaapi.generated.models.statuses import Statuses

class Job(BaseModel):
    """NOTE: This class is auto generated by OpenAPI Generator.
    Ref: https://openapi-generator.tech

    Do not edit the class manually.
    """
    application_id: StrictStr = ...
    callback_url: Optional[StrictStr] = None
    creation_time: datetime = ...
    document_ids: List[StrictStr] = ...
    execute_after_id: Optional[StrictStr] = None
    finished_time: Optional[datetime] = None
    id: StrictStr = ...
    job_type: StrictStr = ...
    model_id: Optional[StrictStr] = None
    parent_job_id: Optional[StrictStr] = None
    reason: Optional[StrictStr] = None
    result: Optional[JobResult] = None
    result_type: Optional[ResultTypes] = None
    starting_time: Optional[datetime] = None
    status: Statuses = ...
    __properties = ["application_id", "callback_url", "creation_time", "document_ids", "execute_after_id", "finished_time", "id", "job_type", "model_id", "parent_job_id", "reason", "result", "result_type", "starting_time", "status"]

    class Config:
        allow_population_by_field_name = True
        validate_assignment = True

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

    def to_json(self) -> str:
        """Returns the JSON representation of the model using alias"""
        return json.dumps(self.to_dict())

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

    def to_dict(self):
        """Returns the dictionary representation of the model using alias"""
        _dict = self.dict(by_alias=True,
                          exclude={
                          },
                          exclude_none=True)
        # override the default output from pydantic by calling `to_dict()` of result
        if self.result:
            _dict['result'] = self.result.to_dict()
        return _dict

    @classmethod
    def from_dict(cls, obj: dict) -> Job:
        """Create an instance of Job from a dict"""
        if obj is None:
            return None

        if type(obj) is not dict:
            return Job.parse_obj(obj)

        _obj = Job.parse_obj({
            "application_id": obj.get("application_id"),
            "callback_url": obj.get("callback_url"),
            "creation_time": obj.get("creation_time"),
            "document_ids": obj.get("document_ids"),
            "execute_after_id": obj.get("execute_after_id"),
            "finished_time": obj.get("finished_time"),
            "id": obj.get("id"),
            "job_type": obj.get("job_type"),
            "model_id": obj.get("model_id"),
            "parent_job_id": obj.get("parent_job_id"),
            "reason": obj.get("reason"),
            "result": JobResult.from_dict(obj.get("result")) if obj.get("result") is not None else None,
            "result_type": obj.get("result_type"),
            "starting_time": obj.get("starting_time"),
            "status": obj.get("status")
        })
        return _obj

