# coding: utf-8

"""
    Mixpeek API

    This is the Mixpeek API, providing access to various endpoints for data processing and retrieval.

    The version of the OpenAPI document: 1.3.0
    Contact: info@mixpeek.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 pydantic import BaseModel, ConfigDict, Field, StrictStr
from typing import Any, ClassVar, Dict, List, Optional
from typing_extensions import Annotated
from mixpeek.models.structured_data_config import StructuredDataConfig
from typing import Optional, Set
from typing_extensions import Self

class SEOConfig(BaseModel):
    """
    SEO configuration for public retriever discoverability.  Auto-generated during publishing with sensible defaults inferred from the retriever's display_config. All fields can be overridden manually.  This configuration controls how the public retriever appears in: - Search engine results (Google, Bing, etc.) - Social media shares (Twitter, Facebook, LinkedIn) - Link previews in messaging apps
    """ # noqa: E501
    meta_title: Optional[Annotated[str, Field(strict=True, max_length=60)]] = Field(default=None, description="SEO-optimized page title (50-60 chars recommended). Auto-generated from display_config.title + site_name if not provided.")
    meta_description: Optional[Annotated[str, Field(strict=True, max_length=160)]] = Field(default=None, description="Meta description for search engine snippets (max 160 chars). Auto-generated from display_config.description if not provided.")
    keywords: Optional[List[StrictStr]] = Field(default=None, description="Relevant keywords for search engines. Auto-inferred from title, description, and retriever tags.")
    og_image_url: Optional[StrictStr] = Field(default=None, description="URL to OG image for social previews (1200x630px recommended). Auto-generated and uploaded to public S3 bucket during publishing.")
    og_image_alt: Optional[Annotated[str, Field(strict=True, max_length=200)]] = Field(default=None, description="Alt text for OG image (accessibility and SEO)")
    og_type: Optional[StrictStr] = Field(default='website', description="Open Graph content type")
    twitter_card: Optional[StrictStr] = Field(default='summary_large_image', description="Twitter card display style")
    twitter_site: Optional[StrictStr] = Field(default='@mixpeek', description="Twitter @handle for the site")
    twitter_creator: Optional[StrictStr] = Field(default=None, description="Twitter @handle for content creator (optional)")
    robots: Optional[StrictStr] = Field(default='index, follow', description="Robots meta directive for search engine crawlers. Use 'noindex, nofollow' to hide from search engines.")
    canonical_url: Optional[StrictStr] = Field(default=None, description="Canonical URL if different from default. Auto-set to https://apps.mixpeek.com/r/{public_name} if not provided.")
    site_name: Optional[StrictStr] = Field(default='Mixpeek', description="Site name for OG tags and branding")
    author: Optional[StrictStr] = Field(default=None, description="Content author/creator name")
    locale: Optional[StrictStr] = Field(default='en_US', description="Content language/locale")
    logo_url: Optional[StrictStr] = Field(default=None, description="URL to organization/brand logo for SEO and branding. Used in structured data and can be displayed in search results.")
    favicon_url: Optional[StrictStr] = Field(default=None, description="URL to favicon/icon for the public retriever page. Recommended sizes: 32x32, 48x48, or 180x180 for Apple touch icon.")
    structured_data: Optional[StructuredDataConfig] = Field(default=None, description="Schema.org structured data for rich search results")
    __properties: ClassVar[List[str]] = ["meta_title", "meta_description", "keywords", "og_image_url", "og_image_alt", "og_type", "twitter_card", "twitter_site", "twitter_creator", "robots", "canonical_url", "site_name", "author", "locale", "logo_url", "favicon_url", "structured_data"]

    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 SEOConfig 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 structured_data
        if self.structured_data:
            _dict['structured_data'] = self.structured_data.to_dict()
        return _dict

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

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

        _obj = cls.model_validate({
            "meta_title": obj.get("meta_title"),
            "meta_description": obj.get("meta_description"),
            "keywords": obj.get("keywords"),
            "og_image_url": obj.get("og_image_url"),
            "og_image_alt": obj.get("og_image_alt"),
            "og_type": obj.get("og_type") if obj.get("og_type") is not None else 'website',
            "twitter_card": obj.get("twitter_card") if obj.get("twitter_card") is not None else 'summary_large_image',
            "twitter_site": obj.get("twitter_site") if obj.get("twitter_site") is not None else '@mixpeek',
            "twitter_creator": obj.get("twitter_creator"),
            "robots": obj.get("robots") if obj.get("robots") is not None else 'index, follow',
            "canonical_url": obj.get("canonical_url"),
            "site_name": obj.get("site_name") if obj.get("site_name") is not None else 'Mixpeek',
            "author": obj.get("author"),
            "locale": obj.get("locale") if obj.get("locale") is not None else 'en_US',
            "logo_url": obj.get("logo_url"),
            "favicon_url": obj.get("favicon_url"),
            "structured_data": StructuredDataConfig.from_dict(obj["structured_data"]) if obj.get("structured_data") is not None else None
        })
        return _obj


