# coding: utf-8

"""
    STACKIT Marketplace API

    API to manage STACKIT Marketplace.

    The version of the OpenAPI document: 1
    Contact: marketplace@stackit.cloud
    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,
    StrictBool,
    StrictStr,
    field_validator,
)
from typing_extensions import Annotated, Self

from stackit.stackitmarketplace.models.assets import Assets
from stackit.stackitmarketplace.models.catalog_product_details_vendor import (
    CatalogProductDetailsVendor,
)
from stackit.stackitmarketplace.models.catalog_product_highlight import (
    CatalogProductHighlight,
)
from stackit.stackitmarketplace.models.catalog_product_pricing_option import (
    CatalogProductPricingOption,
)
from stackit.stackitmarketplace.models.catalog_product_support_resource import (
    CatalogProductSupportResource,
)
from stackit.stackitmarketplace.models.catalog_product_vendor_terms import (
    CatalogProductVendorTerms,
)
from stackit.stackitmarketplace.models.delivery_method import DeliveryMethod
from stackit.stackitmarketplace.models.offer_type import OfferType
from stackit.stackitmarketplace.models.product_lifecycle_state import (
    ProductLifecycleState,
)


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

    assets: Optional[Assets] = None
    categories: Optional[List[StrictStr]] = Field(
        default=None, description="The list of categories associated to the product."
    )
    delivery_method: DeliveryMethod = Field(alias="deliveryMethod")
    demo_url: Optional[Annotated[str, Field(strict=True, max_length=512)]] = Field(
        default=None, description="The URL to a demo if available.", alias="demoUrl"
    )
    description: StrictStr = Field(description="The product description.")
    documentation_url: Annotated[str, Field(strict=True, max_length=512)] = Field(
        description="The documentation URL.", alias="documentationUrl"
    )
    email: Optional[StrictStr] = Field(default=None, description="A e-mail address.")
    has_demo: Optional[StrictBool] = Field(
        default=None, description="If the product has a demoUrl available.", alias="hasDemo"
    )
    has_private_plan_option: Optional[StrictBool] = Field(
        default=None, description="If the product has a private plan option.", alias="hasPrivatePlanOption"
    )
    highlights: List[CatalogProductHighlight] = Field(description="The list of highlights.")
    industries: Optional[List[StrictStr]] = Field(
        default=None, description="The list of industries associated to the product."
    )
    is_product_listing: Optional[StrictBool] = Field(
        default=None,
        description="If true, the product is not fully integrated but only listed. Product listings may not have prices and support information.  Deprecated: Will be removed after 16.12.2025. Please use `offerType` as replacement.",
        alias="isProductListing",
    )
    lifecycle_state: ProductLifecycleState = Field(alias="lifecycleState")
    logo: StrictStr = Field(description="The logo information.")
    name: Annotated[str, Field(strict=True, max_length=512)] = Field(description="The name of the product.")
    offer_type: OfferType = Field(alias="offerType")
    pricing_options: List[CatalogProductPricingOption] = Field(
        description="The list of pricing options.", alias="pricingOptions"
    )
    product_id: Annotated[str, Field(min_length=10, strict=True, max_length=29)] = Field(
        description="The user-readable product ID.", alias="productId"
    )
    summary: StrictStr = Field(description="The short summary of the product.")
    support_faq: Optional[Annotated[str, Field(strict=True, max_length=512)]] = Field(
        default=None, description="The support FAQ URL.", alias="supportFaq"
    )
    support_phone: Optional[StrictStr] = Field(
        default=None, description="The phone number for support inquiries.", alias="supportPhone"
    )
    support_resources: Optional[List[CatalogProductSupportResource]] = Field(
        default=None, description="The list of support resources.", alias="supportResources"
    )
    vendor: CatalogProductDetailsVendor
    vendor_terms: Optional[List[CatalogProductVendorTerms]] = Field(
        default=None, description="The list of terms of use.", alias="vendorTerms"
    )
    video_url: Annotated[str, Field(strict=True, max_length=512)] = Field(
        description="The video URL.", alias="videoUrl"
    )
    __properties: ClassVar[List[str]] = [
        "assets",
        "categories",
        "deliveryMethod",
        "demoUrl",
        "description",
        "documentationUrl",
        "email",
        "hasDemo",
        "hasPrivatePlanOption",
        "highlights",
        "industries",
        "isProductListing",
        "lifecycleState",
        "logo",
        "name",
        "offerType",
        "pricingOptions",
        "productId",
        "summary",
        "supportFaq",
        "supportPhone",
        "supportResources",
        "vendor",
        "vendorTerms",
        "videoUrl",
    ]

    @field_validator("demo_url")
    def demo_url_validate_regular_expression(cls, value):
        """Validates the regular expression"""
        if value is None:
            return value

        if not re.match(r"^(https?:\/\/)?([\da-z\.-]+)\.([a-z\.]{2,6})([\/\w \.-]*)*\/?$", value):
            raise ValueError(
                r"must validate the regular expression /^(https?:\/\/)?([\da-z\.-]+)\.([a-z\.]{2,6})([\/\w \.-]*)*\/?$/"
            )
        return value

    @field_validator("documentation_url")
    def documentation_url_validate_regular_expression(cls, value):
        """Validates the regular expression"""
        if not re.match(r"^(https?:\/\/)?([\da-z\.-]+)\.([a-z\.]{2,6})([\/\w \.-]*)*\/?$", value):
            raise ValueError(
                r"must validate the regular expression /^(https?:\/\/)?([\da-z\.-]+)\.([a-z\.]{2,6})([\/\w \.-]*)*\/?$/"
            )
        return value

    @field_validator("name")
    def name_validate_regular_expression(cls, value):
        """Validates the regular expression"""
        if not re.match(r"^[a-zA-ZäüöÄÜÖ0-9,.!?()@\/:=\n\t -]+$", value):
            raise ValueError(r"must validate the regular expression /^[a-zA-ZäüöÄÜÖ0-9,.!?()@\/:=\n\t -]+$/")
        return value

    @field_validator("product_id")
    def product_id_validate_regular_expression(cls, value):
        """Validates the regular expression"""
        if not re.match(r"^[a-z0-9-]{1,20}-[0-9a-f]{8}$", value):
            raise ValueError(r"must validate the regular expression /^[a-z0-9-]{1,20}-[0-9a-f]{8}$/")
        return value

    @field_validator("support_faq")
    def support_faq_validate_regular_expression(cls, value):
        """Validates the regular expression"""
        if value is None:
            return value

        if not re.match(r"^(https?:\/\/)?([\da-z\.-]+)\.([a-z\.]{2,6})([\/\w \.-]*)*\/?$", value):
            raise ValueError(
                r"must validate the regular expression /^(https?:\/\/)?([\da-z\.-]+)\.([a-z\.]{2,6})([\/\w \.-]*)*\/?$/"
            )
        return value

    @field_validator("video_url")
    def video_url_validate_regular_expression(cls, value):
        """Validates the regular expression"""
        if not re.match(r"^(https?:\/\/)?([\da-z\.-]+)\.([a-z\.]{2,6})([\/\w \.-]*)*\/?$", value):
            raise ValueError(
                r"must validate the regular expression /^(https?:\/\/)?([\da-z\.-]+)\.([a-z\.]{2,6})([\/\w \.-]*)*\/?$/"
            )
        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 CatalogProductDetail 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 assets
        if self.assets:
            _dict["assets"] = self.assets.to_dict()
        # override the default output from pydantic by calling `to_dict()` of each item in highlights (list)
        _items = []
        if self.highlights:
            for _item in self.highlights:
                if _item:
                    _items.append(_item.to_dict())
            _dict["highlights"] = _items
        # override the default output from pydantic by calling `to_dict()` of each item in pricing_options (list)
        _items = []
        if self.pricing_options:
            for _item in self.pricing_options:
                if _item:
                    _items.append(_item.to_dict())
            _dict["pricingOptions"] = _items
        # override the default output from pydantic by calling `to_dict()` of each item in support_resources (list)
        _items = []
        if self.support_resources:
            for _item in self.support_resources:
                if _item:
                    _items.append(_item.to_dict())
            _dict["supportResources"] = _items
        # override the default output from pydantic by calling `to_dict()` of vendor
        if self.vendor:
            _dict["vendor"] = self.vendor.to_dict()
        # override the default output from pydantic by calling `to_dict()` of each item in vendor_terms (list)
        _items = []
        if self.vendor_terms:
            for _item in self.vendor_terms:
                if _item:
                    _items.append(_item.to_dict())
            _dict["vendorTerms"] = _items
        return _dict

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

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

        _obj = cls.model_validate(
            {
                "assets": Assets.from_dict(obj["assets"]) if obj.get("assets") is not None else None,
                "categories": obj.get("categories"),
                "deliveryMethod": obj.get("deliveryMethod"),
                "demoUrl": obj.get("demoUrl"),
                "description": obj.get("description"),
                "documentationUrl": obj.get("documentationUrl"),
                "email": obj.get("email"),
                "hasDemo": obj.get("hasDemo"),
                "hasPrivatePlanOption": obj.get("hasPrivatePlanOption"),
                "highlights": (
                    [CatalogProductHighlight.from_dict(_item) for _item in obj["highlights"]]
                    if obj.get("highlights") is not None
                    else None
                ),
                "industries": obj.get("industries"),
                "isProductListing": obj.get("isProductListing"),
                "lifecycleState": obj.get("lifecycleState"),
                "logo": obj.get("logo"),
                "name": obj.get("name"),
                "offerType": obj.get("offerType"),
                "pricingOptions": (
                    [CatalogProductPricingOption.from_dict(_item) for _item in obj["pricingOptions"]]
                    if obj.get("pricingOptions") is not None
                    else None
                ),
                "productId": obj.get("productId"),
                "summary": obj.get("summary"),
                "supportFaq": obj.get("supportFaq"),
                "supportPhone": obj.get("supportPhone"),
                "supportResources": (
                    [CatalogProductSupportResource.from_dict(_item) for _item in obj["supportResources"]]
                    if obj.get("supportResources") is not None
                    else None
                ),
                "vendor": (
                    CatalogProductDetailsVendor.from_dict(obj["vendor"]) if obj.get("vendor") is not None else None
                ),
                "vendorTerms": (
                    [CatalogProductVendorTerms.from_dict(_item) for _item in obj["vendorTerms"]]
                    if obj.get("vendorTerms") is not None
                    else None
                ),
                "videoUrl": obj.get("videoUrl"),
            }
        )
        return _obj
