# coding: utf-8

"""
    InductivaWebAPI

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

    The version of the OpenAPI document: 0.1.0
    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, StrictFloat, StrictInt, StrictStr
from typing import Any, ClassVar, Dict, List, Optional, Union
from typing import Optional, Set
from typing_extensions import Self


class UsageStatistics(BaseModel):
    """
    UsageStatistics
    """

  # noqa: E501
    period: Optional[StrictStr] = None
    total_core_hours_failed: Optional[Union[StrictFloat, StrictInt]] = None
    total_core_hours: Optional[Union[StrictFloat, StrictInt]] = None
    total_tasks: Optional[StrictInt] = None
    total_failed_tasks: Optional[StrictInt] = None
    avg_total_tasks_duration: Optional[Union[StrictFloat, StrictInt]] = None
    avg_computation_seconds_task_duration: Optional[Union[StrictFloat,
                                                          StrictInt]] = None
    success_rate: Optional[Union[StrictFloat, StrictInt]] = None
    avg_estimated_cost: Optional[Union[StrictFloat, StrictInt]] = None
    total_estimated_cost: Optional[Union[StrictFloat, StrictInt]] = None
    total_failed_cost: Optional[Union[StrictFloat, StrictInt]] = None
    __properties: ClassVar[List[str]] = [
        "period", "total_core_hours_failed", "total_core_hours", "total_tasks",
        "total_failed_tasks", "avg_total_tasks_duration",
        "avg_computation_seconds_task_duration", "success_rate",
        "avg_estimated_cost", "total_estimated_cost", "total_failed_cost"
    ]

    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 UsageStatistics 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,
        )
        # set to None if period (nullable) is None
        # and model_fields_set contains the field
        if self.period is None and "period" in self.model_fields_set:
            _dict['period'] = None

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

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

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

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

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

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

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

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

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

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

        return _dict

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

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

        _obj = cls.model_validate({
            "period":
                obj.get("period"),
            "total_core_hours_failed":
                obj.get("total_core_hours_failed"),
            "total_core_hours":
                obj.get("total_core_hours"),
            "total_tasks":
                obj.get("total_tasks"),
            "total_failed_tasks":
                obj.get("total_failed_tasks"),
            "avg_total_tasks_duration":
                obj.get("avg_total_tasks_duration"),
            "avg_computation_seconds_task_duration":
                obj.get("avg_computation_seconds_task_duration"),
            "success_rate":
                obj.get("success_rate"),
            "avg_estimated_cost":
                obj.get("avg_estimated_cost"),
            "total_estimated_cost":
                obj.get("total_estimated_cost"),
            "total_failed_cost":
                obj.get("total_failed_cost")
        })
        return _obj
