# coding: utf-8

"""
    Pinterest REST API

    Pinterest's REST API

    The version of the OpenAPI document: 5.23.0
    Contact: blah+oapicf@cliffano.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, field_validator
from typing import Any, ClassVar, Dict, List, Optional
from typing_extensions import Annotated
from pinterestsdk.models.conversion_attribution_window_days import ConversionAttributionWindowDays
from pinterestsdk.models.conversion_product_reporting_column import ConversionProductReportingColumn
from pinterestsdk.models.conversion_report_time_type import ConversionReportTimeType
from pinterestsdk.models.objective_type import ObjectiveType
from typing import Optional, Set
from typing_extensions import Self

class ConversionProductReportRequest(BaseModel):
    """
    Request for a brand, category, SKU report
    """ # noqa: E501
    ad_group_ids: Optional[Annotated[List[Annotated[str, Field(strict=True)]], Field(min_length=1, max_length=500)]] = Field(default=None, description="List of ad group ids. <br>Only support ad_group_ids field when level of the report is AD_GROUP.")
    campaign_ids: Optional[Annotated[List[Annotated[str, Field(strict=True)]], Field(min_length=1, max_length=500)]] = Field(default=None, description="List of campaign ids. <br>Only support campaign_ids field when level of the report is CAMPAIGN.")
    campaign_objective_types: Optional[Annotated[List[ObjectiveType], Field(min_length=1, max_length=7)]] = Field(default=None, description="List of values for filtering. Default is ['CONSIDERATION','AWARENESS','WEB_CONVERSION','VIDEO_COMPLETION'].")
    click_window_days: Optional[ConversionAttributionWindowDays] = Field(default=ConversionAttributionWindowDays.NUMBER_30, description="Number of days to use as the conversion attribution window for a pin click action. Applies to Pinterest Tag conversion metrics. Prior conversion tags use their defined attribution windows. If not specified, defaults to `30` days.")
    columns: List[ConversionProductReportingColumn] = Field(description="Metric and entity columns")
    conversion_product_attribution_type: Optional[StrictStr] = None
    conversion_product_breakdown: Optional[StrictStr] = None
    conversion_report_time: Optional[ConversionReportTimeType] = Field(default='TIME_OF_AD_ACTION', description="The date by which the conversion metrics returned from this endpoint will be reported. There are two dates associated with a conversion event: the date that the user interacted with the ad, and the date that the user completed a conversion event.")
    end_date: Annotated[str, Field(strict=True)] = Field(description="Metric report end date (UTC). Format: YYYY-MM-DD.<br> A max of 1 year is allowed between the start and end date for reports.")
    granularity: StrictStr = Field(description="TOTAL - metrics are aggregated over the specified date range.<br> WEEK - metrics are broken down weekly.<br> MONTH - metrics are broken down monthly.")
    level: StrictStr = Field(description="Level of the report")
    product_sku_ids: Optional[Annotated[List[Annotated[str, Field(strict=True)]], Field(min_length=2, max_length=500)]] = Field(default=None, description="List of SKU ids. <br>Only support product_sku_ids field when report breakdown type is PRODUCT_SKU_GROUP.")
    report_name: StrictStr = Field(description="Name of the conversion product report.")
    start_date: Annotated[str, Field(strict=True)] = Field(description="Metric report start date (UTC). Format: YYYY-MM-DD.<br> Start date must be after 2024-03-16. 7 day minimum time window for report is required.")
    view_window_days: Optional[ConversionAttributionWindowDays] = Field(default=ConversionAttributionWindowDays.NUMBER_30, description="Number of days to use as the conversion attribution window for a view action. Applies to Pinterest Tag conversion metrics. Prior conversion tags use their defined attribution windows. If not specified, defaults to `30` day.")
    __properties: ClassVar[List[str]] = ["ad_group_ids", "campaign_ids", "campaign_objective_types", "click_window_days", "columns", "conversion_product_attribution_type", "conversion_product_breakdown", "conversion_report_time", "end_date", "granularity", "level", "product_sku_ids", "report_name", "start_date", "view_window_days"]

    @field_validator('conversion_product_attribution_type')
    def conversion_product_attribution_type_validate_enum(cls, value):
        """Validates the enum"""
        if value is None:
            return value

        if value not in set(['DEFAULT', 'BRAND_ATTRIBUTION']):
            raise ValueError("must be one of enum values ('DEFAULT', 'BRAND_ATTRIBUTION')")
        return value

    @field_validator('conversion_product_breakdown')
    def conversion_product_breakdown_validate_enum(cls, value):
        """Validates the enum"""
        if value is None:
            return value

        if value not in set(['PRODUCT_BRAND', 'PRODUCT_CATEGORY', 'PRODUCT_BRAND_AND_CATEGORY', 'PRODUCT_SKU', 'PRODUCT_SKU_GROUP']):
            raise ValueError("must be one of enum values ('PRODUCT_BRAND', 'PRODUCT_CATEGORY', 'PRODUCT_BRAND_AND_CATEGORY', 'PRODUCT_SKU', 'PRODUCT_SKU_GROUP')")
        return value

    @field_validator('end_date')
    def end_date_validate_regular_expression(cls, value):
        """Validates the regular expression"""
        if not re.match(r"^(\d{4})-(\d{2})-(\d{2})$", value):
            raise ValueError(r"must validate the regular expression /^(\d{4})-(\d{2})-(\d{2})$/")
        return value

    @field_validator('granularity')
    def granularity_validate_enum(cls, value):
        """Validates the enum"""
        if value not in set(['WEEK', 'MONTH', 'TOTAL']):
            raise ValueError("must be one of enum values ('WEEK', 'MONTH', 'TOTAL')")
        return value

    @field_validator('level')
    def level_validate_enum(cls, value):
        """Validates the enum"""
        if value not in set(['ADVERTISER', 'CAMPAIGN', 'AD_GROUP']):
            raise ValueError("must be one of enum values ('ADVERTISER', 'CAMPAIGN', 'AD_GROUP')")
        return value

    @field_validator('start_date')
    def start_date_validate_regular_expression(cls, value):
        """Validates the regular expression"""
        if not re.match(r"^(\d{4})-(\d{2})-(\d{2})$", value):
            raise ValueError(r"must validate the regular expression /^(\d{4})-(\d{2})-(\d{2})$/")
        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 ConversionProductReportRequest 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,
        )
        return _dict

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

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

        _obj = cls.model_validate({
            "ad_group_ids": obj.get("ad_group_ids"),
            "campaign_ids": obj.get("campaign_ids"),
            "campaign_objective_types": obj.get("campaign_objective_types"),
            "click_window_days": obj.get("click_window_days") if obj.get("click_window_days") is not None else ConversionAttributionWindowDays.NUMBER_30,
            "columns": obj.get("columns"),
            "conversion_product_attribution_type": obj.get("conversion_product_attribution_type"),
            "conversion_product_breakdown": obj.get("conversion_product_breakdown"),
            "conversion_report_time": obj.get("conversion_report_time") if obj.get("conversion_report_time") is not None else 'TIME_OF_AD_ACTION',
            "end_date": obj.get("end_date"),
            "granularity": obj.get("granularity"),
            "level": obj.get("level"),
            "product_sku_ids": obj.get("product_sku_ids"),
            "report_name": obj.get("report_name"),
            "start_date": obj.get("start_date"),
            "view_window_days": obj.get("view_window_days") if obj.get("view_window_days") is not None else ConversionAttributionWindowDays.NUMBER_30
        })
        return _obj


