# coding: utf-8

"""
    FlowHunt

    FlowHunt API

    The version of the OpenAPI document: 2.0.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 datetime import datetime
from pydantic import BaseModel, ConfigDict, StrictBool, StrictStr
from typing import Any, ClassVar, Dict, List, Optional
from flowhunt.models.url_screenshot_response import UrlScreenshotResponse
from typing import Optional, Set
from typing_extensions import Self

class ScheduleUrlResponse(BaseModel):
    """
    ScheduleUrlResponse
    """ # noqa: E501
    schedule_id: StrictStr
    domain_id: StrictStr
    url_id: StrictStr
    url: StrictStr
    last_text_timestamp: Optional[datetime]
    page_screenshot: Optional[UrlScreenshotResponse]
    url_title: Optional[StrictStr]
    url_meta_description: Optional[StrictStr]
    url_og_image: Optional[StrictStr]
    is_original_url: StrictBool
    dest_url_id: Optional[StrictStr]
    created_at: datetime
    __properties: ClassVar[List[str]] = ["schedule_id", "domain_id", "url_id", "url", "last_text_timestamp", "page_screenshot", "url_title", "url_meta_description", "url_og_image", "is_original_url", "dest_url_id", "created_at"]

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

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

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

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

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

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

        return _dict

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

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

        _obj = cls.model_validate({
            "schedule_id": obj.get("schedule_id"),
            "domain_id": obj.get("domain_id"),
            "url_id": obj.get("url_id"),
            "url": obj.get("url"),
            "last_text_timestamp": obj.get("last_text_timestamp"),
            "page_screenshot": UrlScreenshotResponse.from_dict(obj["page_screenshot"]) if obj.get("page_screenshot") is not None else None,
            "url_title": obj.get("url_title"),
            "url_meta_description": obj.get("url_meta_description"),
            "url_og_image": obj.get("url_og_image"),
            "is_original_url": obj.get("is_original_url"),
            "dest_url_id": obj.get("dest_url_id"),
            "created_at": obj.get("created_at")
        })
        return _obj


