# coding: utf-8

"""
    Sentience API

    API Gateway for Sentience Platform - Web Content Extraction and Element Coordinate Mapping

    The version of the OpenAPI document: 1.0.0
    Contact: support@sentienceapi.com
    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, field_validator
from typing import Any, ClassVar, Dict, List, Optional
from sentience_sdk.models.sentience_applied_filters import SentienceAppliedFilters
from sentience_sdk.models.sentience_interactable_element import SentienceInteractableElement
from sentience_sdk.models.sentience_layout_viewport import SentienceLayoutViewport
from sentience_sdk.models.sentience_proxy_failure import SentienceProxyFailure
from sentience_sdk.models.sentience_render_quality import SentienceRenderQuality
from typing import Optional, Set
from typing_extensions import Self

class SentienceMapModeResponse(BaseModel):
    """
    Response for 'map' mode
    """ # noqa: E501
    mode: StrictStr
    status: StrictStr
    engine: Optional[SentienceRenderQuality] = SentienceRenderQuality.PERFORMANCE
    url: StrictStr
    layout_viewport: Optional[SentienceLayoutViewport] = None
    interactable_elements: List[SentienceInteractableElement]
    timestamp: Optional[datetime] = None
    total_elements_extracted: Optional[StrictInt] = None
    filters_applied: Optional[SentienceAppliedFilters] = None
    proxy_failure: Optional[SentienceProxyFailure] = None
    __properties: ClassVar[List[str]] = ["mode", "status", "engine", "url", "layout_viewport", "interactable_elements", "timestamp", "total_elements_extracted", "filters_applied", "proxy_failure"]

    @field_validator('mode')
    def mode_validate_enum(cls, value):
        """Validates the enum"""
        if value not in set(['map']):
            raise ValueError("must be one of enum values ('map')")
        return value

    @field_validator('status')
    def status_validate_enum(cls, value):
        """Validates the enum"""
        if value not in set(['success', 'error']):
            raise ValueError("must be one of enum values ('success', 'error')")
        return value

    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 SentienceMapModeResponse 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 layout_viewport
        if self.layout_viewport:
            _dict['layout_viewport'] = self.layout_viewport.to_dict()
        # override the default output from pydantic by calling `to_dict()` of each item in interactable_elements (list)
        _items = []
        if self.interactable_elements:
            for _item_interactable_elements in self.interactable_elements:
                if _item_interactable_elements:
                    _items.append(_item_interactable_elements.to_dict())
            _dict['interactable_elements'] = _items
        # override the default output from pydantic by calling `to_dict()` of filters_applied
        if self.filters_applied:
            _dict['filters_applied'] = self.filters_applied.to_dict()
        # override the default output from pydantic by calling `to_dict()` of proxy_failure
        if self.proxy_failure:
            _dict['proxy_failure'] = self.proxy_failure.to_dict()
        return _dict

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

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

        _obj = cls.model_validate({
            "mode": obj.get("mode") if obj.get("mode") is not None else 'map',
            "status": obj.get("status"),
            "engine": obj.get("engine") if obj.get("engine") is not None else SentienceRenderQuality.PERFORMANCE,
            "url": obj.get("url"),
            "layout_viewport": SentienceLayoutViewport.from_dict(obj["layout_viewport"]) if obj.get("layout_viewport") is not None else None,
            "interactable_elements": [SentienceInteractableElement.from_dict(_item) for _item in obj["interactable_elements"]] if obj.get("interactable_elements") is not None else None,
            "timestamp": obj.get("timestamp"),
            "total_elements_extracted": obj.get("total_elements_extracted"),
            "filters_applied": SentienceAppliedFilters.from_dict(obj["filters_applied"]) if obj.get("filters_applied") is not None else None,
            "proxy_failure": SentienceProxyFailure.from_dict(obj["proxy_failure"]) if obj.get("proxy_failure") is not None else None
        })
        return _obj


