# coding: utf-8

"""
    ToolHub Customer API

    REST API for customer access to ToolHub well data.  ## Authentication  All endpoints require Bearer token authentication using an API key:  ``` Authorization: Bearer thub_live_xxxxxxxxxxxxxxxxxxxx ```  API keys are issued per-organization and inherit well access permissions.  ## Rate Limits  - Standard tier: 70 requests/minute - Premium tier: 300 requests/minute

    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 em_toolhub.models.get_well200_response_body_data_wellbores_inner import GetWell200ResponseBodyDataWellboresInner
from typing import Optional, Set
from typing_extensions import Self

class GetWell200ResponseBodyData(BaseModel):
    """
    GetWell200ResponseBodyData
    """ # noqa: E501
    id: StrictStr
    name: Optional[StrictStr]
    project_name: Optional[StrictStr]
    slug: StrictStr
    field_name: Optional[StrictStr]
    latitude: Optional[Union[StrictFloat, StrictInt]]
    longitude: Optional[Union[StrictFloat, StrictInt]]
    created_at: StrictStr
    wellbores: List[GetWell200ResponseBodyDataWellboresInner]
    __properties: ClassVar[List[str]] = ["id", "name", "project_name", "slug", "field_name", "latitude", "longitude", "created_at", "wellbores"]

    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 GetWell200ResponseBodyData 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 wellbores (list)
        _items = []
        if self.wellbores:
            for _item_wellbores in self.wellbores:
                if _item_wellbores:
                    _items.append(_item_wellbores.to_dict())
            _dict['wellbores'] = _items
        # set to None if name (nullable) is None
        # and model_fields_set contains the field
        if self.name is None and "name" in self.model_fields_set:
            _dict['name'] = None

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

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

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

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

        return _dict

    @classmethod
    def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
        """Create an instance of GetWell200ResponseBodyData 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"),
            "project_name": obj.get("project_name"),
            "slug": obj.get("slug"),
            "field_name": obj.get("field_name"),
            "latitude": obj.get("latitude"),
            "longitude": obj.get("longitude"),
            "created_at": obj.get("created_at"),
            "wellbores": [GetWell200ResponseBodyDataWellboresInner.from_dict(_item) for _item in obj["wellbores"]] if obj.get("wellbores") is not None else None
        })
        return _obj


