# coding: utf-8

"""
Perigon API

The Perigon API provides access to comprehensive news and web content data. To use the API, simply sign up for a Perigon Business Solutions account to obtain your API key. Your available features may vary based on your plan. See the Authentication section for details on how to use your API key.

The version of the OpenAPI document: 1.0.0
Contact: data@perigon.io
Generated by OpenAPI Generator (https://openapi-generator.tech)

Do not edit the class manually.
"""  # noqa: E501


from __future__ import annotations

import json
import pprint
import re  # noqa: F401
from typing import Any, ClassVar, Dict, List, Optional, Set

from pydantic import BaseModel, ConfigDict, Field, StrictInt, StrictStr
from typing_extensions import Self

from perigon.models.location_holder import LocationHolder
from perigon.models.name_count import NameCount


class Journalist(BaseModel):
    """
    Journalist
    """  # noqa: E501

    id: Optional[StrictStr] = None
    name: Optional[StrictStr] = None
    full_name: Optional[StrictStr] = Field(default=None, alias="fullName")
    headline: Optional[StrictStr] = None
    description: Optional[StrictStr] = None
    title: Optional[StrictStr] = None
    locations: Optional[List[LocationHolder]] = None
    updated_at: Optional[StrictStr] = Field(default=None, alias="updatedAt")
    top_topics: Optional[List[NameCount]] = Field(default=None, alias="topTopics")
    top_sources: Optional[List[NameCount]] = Field(default=None, alias="topSources")
    top_categories: Optional[List[NameCount]] = Field(
        default=None, alias="topCategories"
    )
    top_labels: Optional[List[NameCount]] = Field(default=None, alias="topLabels")
    top_countries: Optional[List[NameCount]] = Field(default=None, alias="topCountries")
    avg_monthly_posts: Optional[StrictInt] = Field(
        default=None, alias="avgMonthlyPosts"
    )
    twitter_handle: Optional[StrictStr] = Field(default=None, alias="twitterHandle")
    twitter_bio: Optional[StrictStr] = Field(default=None, alias="twitterBio")
    image_url: Optional[StrictStr] = Field(default=None, alias="imageUrl")
    linkedin_url: Optional[StrictStr] = Field(default=None, alias="linkedinUrl")
    linkedin_connections: Optional[StrictInt] = Field(
        default=None, alias="linkedinConnections"
    )
    linkedin_followers: Optional[StrictInt] = Field(
        default=None, alias="linkedinFollowers"
    )
    facebook_url: Optional[StrictStr] = Field(default=None, alias="facebookUrl")
    instagram_url: Optional[StrictStr] = Field(default=None, alias="instagramUrl")
    website_url: Optional[StrictStr] = Field(default=None, alias="websiteUrl")
    blog_url: Optional[StrictStr] = Field(default=None, alias="blogUrl")
    tumblr_url: Optional[StrictStr] = Field(default=None, alias="tumblrUrl")
    youtube_url: Optional[StrictStr] = Field(default=None, alias="youtubeUrl")
    __properties: ClassVar[List[str]] = [
        "id",
        "name",
        "fullName",
        "headline",
        "description",
        "title",
        "locations",
        "updatedAt",
        "topTopics",
        "topSources",
        "topCategories",
        "topLabels",
        "topCountries",
        "avgMonthlyPosts",
        "twitterHandle",
        "twitterBio",
        "imageUrl",
        "linkedinUrl",
        "linkedinConnections",
        "linkedinFollowers",
        "facebookUrl",
        "instagramUrl",
        "websiteUrl",
        "blogUrl",
        "tumblrUrl",
        "youtubeUrl",
    ]

    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 Journalist 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 locations (list)
        _items = []
        if self.locations:
            for _item_locations in self.locations:
                if _item_locations:
                    _items.append(_item_locations.to_dict())
            _dict["locations"] = _items
        # override the default output from pydantic by calling `to_dict()` of each item in top_topics (list)
        _items = []
        if self.top_topics:
            for _item_top_topics in self.top_topics:
                if _item_top_topics:
                    _items.append(_item_top_topics.to_dict())
            _dict["topTopics"] = _items
        # override the default output from pydantic by calling `to_dict()` of each item in top_sources (list)
        _items = []
        if self.top_sources:
            for _item_top_sources in self.top_sources:
                if _item_top_sources:
                    _items.append(_item_top_sources.to_dict())
            _dict["topSources"] = _items
        # override the default output from pydantic by calling `to_dict()` of each item in top_categories (list)
        _items = []
        if self.top_categories:
            for _item_top_categories in self.top_categories:
                if _item_top_categories:
                    _items.append(_item_top_categories.to_dict())
            _dict["topCategories"] = _items
        # override the default output from pydantic by calling `to_dict()` of each item in top_labels (list)
        _items = []
        if self.top_labels:
            for _item_top_labels in self.top_labels:
                if _item_top_labels:
                    _items.append(_item_top_labels.to_dict())
            _dict["topLabels"] = _items
        # override the default output from pydantic by calling `to_dict()` of each item in top_countries (list)
        _items = []
        if self.top_countries:
            for _item_top_countries in self.top_countries:
                if _item_top_countries:
                    _items.append(_item_top_countries.to_dict())
            _dict["topCountries"] = _items
        # set to None if id (nullable) is None
        # and model_fields_set contains the field
        if self.id is None and "id" in self.model_fields_set:
            _dict["id"] = None

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        return _dict

    @classmethod
    def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
        """Create an instance of Journalist 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"),
                "fullName": obj.get("fullName"),
                "headline": obj.get("headline"),
                "description": obj.get("description"),
                "title": obj.get("title"),
                "locations": (
                    [LocationHolder.from_dict(_item) for _item in obj["locations"]]
                    if obj.get("locations") is not None
                    else None
                ),
                "updatedAt": obj.get("updatedAt"),
                "topTopics": (
                    [NameCount.from_dict(_item) for _item in obj["topTopics"]]
                    if obj.get("topTopics") is not None
                    else None
                ),
                "topSources": (
                    [NameCount.from_dict(_item) for _item in obj["topSources"]]
                    if obj.get("topSources") is not None
                    else None
                ),
                "topCategories": (
                    [NameCount.from_dict(_item) for _item in obj["topCategories"]]
                    if obj.get("topCategories") is not None
                    else None
                ),
                "topLabels": (
                    [NameCount.from_dict(_item) for _item in obj["topLabels"]]
                    if obj.get("topLabels") is not None
                    else None
                ),
                "topCountries": (
                    [NameCount.from_dict(_item) for _item in obj["topCountries"]]
                    if obj.get("topCountries") is not None
                    else None
                ),
                "avgMonthlyPosts": obj.get("avgMonthlyPosts"),
                "twitterHandle": obj.get("twitterHandle"),
                "twitterBio": obj.get("twitterBio"),
                "imageUrl": obj.get("imageUrl"),
                "linkedinUrl": obj.get("linkedinUrl"),
                "linkedinConnections": obj.get("linkedinConnections"),
                "linkedinFollowers": obj.get("linkedinFollowers"),
                "facebookUrl": obj.get("facebookUrl"),
                "instagramUrl": obj.get("instagramUrl"),
                "websiteUrl": obj.get("websiteUrl"),
                "blogUrl": obj.get("blogUrl"),
                "tumblrUrl": obj.get("tumblrUrl"),
                "youtubeUrl": obj.get("youtubeUrl"),
            }
        )
        return _obj
