# 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, StrictFloat, StrictInt, StrictStr, field_validator
from typing import Any, ClassVar, Dict, List, Optional, Union
from typing_extensions import Annotated
from pinterestsdk.models.currency import Currency
from typing import Optional, Set
from typing_extensions import Self

class SSIOCreateInsertionOrderRequest(BaseModel):
    """
    SSIOCreateInsertionOrderRequest
    """ # noqa: E501
    agency_link: Optional[StrictStr] = Field(default=None, description="URL link for agency")
    billing_contact_email: StrictStr = Field(description="The billing contact email")
    billing_contact_firstname: StrictStr = Field(description="The billing contact first name")
    billing_contact_lastname: StrictStr = Field(description="The billing contact last name")
    budget_amount: Optional[Union[StrictFloat, StrictInt]] = Field(default=None, description="If Budget order line, the budget amount.")
    end_date: Optional[Annotated[str, Field(strict=True)]] = Field(default=None, description="End date of time period. Format: YYYY-MM-DD")
    media_contact_email: StrictStr = Field(description="The media contact email")
    media_contact_firstname: StrictStr = Field(description="The media contact first name")
    media_contact_lastname: StrictStr = Field(description="The media contact last name")
    po_number: StrictStr = Field(description="The po number")
    start_date: Annotated[str, Field(strict=True)] = Field(description="Starting date of time period. Format: YYYY-MM-DD")
    user_email: Optional[StrictStr] = Field(default=None, description="The email of user submitting the insertion order")
    accepted_terms_id: StrictStr = Field(description="The SFDC id for the terms")
    accepted_terms_time: Optional[StrictInt] = Field(default=None, description="The UTC timestamp (to the nearest sec) of when terms were accepted")
    billto_billing_address_id: StrictStr = Field(description="The bill-to billing address id")
    billto_business_address_id: StrictStr = Field(description="The bill-to business address id")
    billto_company_id: StrictStr = Field(description="The bill-to company id")
    currency_info: Currency
    estimated_monthly_spend: Optional[Union[StrictFloat, StrictInt]] = Field(default=None, description="If Ongoing (perpetual) order line, the estimated monthly spend")
    order_line_type: StrictStr = Field(description="Type can be Budget or Perpetual")
    order_name: StrictStr = Field(description="The order name")
    pmp_id: StrictStr = Field(description="The pmp id")
    __properties: ClassVar[List[str]] = ["agency_link", "billing_contact_email", "billing_contact_firstname", "billing_contact_lastname", "budget_amount", "end_date", "media_contact_email", "media_contact_firstname", "media_contact_lastname", "po_number", "start_date", "user_email", "accepted_terms_id", "accepted_terms_time", "billto_billing_address_id", "billto_business_address_id", "billto_company_id", "currency_info", "estimated_monthly_spend", "order_line_type", "order_name", "pmp_id"]

    @field_validator('end_date')
    def end_date_validate_regular_expression(cls, value):
        """Validates the regular expression"""
        if value is None:
            return value

        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('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

    @field_validator('order_line_type')
    def order_line_type_validate_enum(cls, value):
        """Validates the enum"""
        if value not in set(['BUDGET', 'PERPETUALS']):
            raise ValueError("must be one of enum values ('BUDGET', 'PERPETUALS')")
        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 SSIOCreateInsertionOrderRequest 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 SSIOCreateInsertionOrderRequest from a dict"""
        if obj is None:
            return None

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

        _obj = cls.model_validate({
            "agency_link": obj.get("agency_link"),
            "billing_contact_email": obj.get("billing_contact_email"),
            "billing_contact_firstname": obj.get("billing_contact_firstname"),
            "billing_contact_lastname": obj.get("billing_contact_lastname"),
            "budget_amount": obj.get("budget_amount"),
            "end_date": obj.get("end_date"),
            "media_contact_email": obj.get("media_contact_email"),
            "media_contact_firstname": obj.get("media_contact_firstname"),
            "media_contact_lastname": obj.get("media_contact_lastname"),
            "po_number": obj.get("po_number"),
            "start_date": obj.get("start_date"),
            "user_email": obj.get("user_email"),
            "accepted_terms_id": obj.get("accepted_terms_id"),
            "accepted_terms_time": obj.get("accepted_terms_time"),
            "billto_billing_address_id": obj.get("billto_billing_address_id"),
            "billto_business_address_id": obj.get("billto_business_address_id"),
            "billto_company_id": obj.get("billto_company_id"),
            "currency_info": obj.get("currency_info"),
            "estimated_monthly_spend": obj.get("estimated_monthly_spend"),
            "order_line_type": obj.get("order_line_type"),
            "order_name": obj.get("order_name"),
            "pmp_id": obj.get("pmp_id")
        })
        return _obj


