# coding: utf-8

"""
    backend

    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 datetime import datetime
from pydantic import BaseModel, ConfigDict, StrictInt, StrictStr
from typing import Any, ClassVar, Dict, List, Optional
from typing import Optional, Set
from typing_extensions import Self

class NewsItem(BaseModel):
    """
    NewsItem
    """ # noqa: E501
    published_date: datetime
    provider: StrictStr
    news_item_id: StrictStr
    headline: StrictStr
    subheadline: Optional[StrictStr] = None
    author: StrictStr
    country: StrictStr
    city: Optional[StrictStr] = None
    region: Optional[StrictStr] = None
    word_count: Optional[StrictInt] = None
    content: StrictStr
    media: Optional[List[StrictStr]] = None
    topics: Optional[List[StrictStr]] = None
    __properties: ClassVar[List[str]] = ["published_date", "provider", "news_item_id", "headline", "subheadline", "author", "country", "city", "region", "word_count", "content", "media", "topics"]

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

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

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

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

        return _dict

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

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

        _obj = cls.model_validate({
            "published_date": obj.get("published_date"),
            "provider": obj.get("provider"),
            "news_item_id": obj.get("news_item_id"),
            "headline": obj.get("headline"),
            "subheadline": obj.get("subheadline"),
            "author": obj.get("author"),
            "country": obj.get("country"),
            "city": obj.get("city"),
            "region": obj.get("region"),
            "word_count": obj.get("word_count"),
            "content": obj.get("content"),
            "media": obj.get("media"),
            "topics": obj.get("topics")
        })
        return _obj


