# 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 datetime import date
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 SSIOOrderLine(BaseModel):
    """
    SSIOOrderLine
    """ # noqa: E501
    accepted_terms_id: Optional[StrictStr] = Field(default=None, description="The SFDC id for the terms")
    accepted_terms_time: Optional[Annotated[str, Field(strict=True)]] = Field(default=None, description="The UTC timestamp (to the nearest sec) of when terms were accepted")
    ads_manager_order_line_id: Optional[StrictStr] = Field(default=None, description="Ads manager OrderLineId")
    agency_link: Optional[StrictStr] = Field(default=None, description="Agency link")
    bill_to_company_name: Optional[StrictStr] = Field(default=None, description="Bill To Company name")
    billing_contact_email: Optional[StrictStr] = Field(default=None, description="Billing contact email")
    billing_contact_firstname: Optional[StrictStr] = Field(default=None, description="Billing contact first name")
    billing_contact_lastname: Optional[StrictStr] = Field(default=None, description="Billing contact last name")
    budget_amount: Optional[Union[StrictFloat, StrictInt]] = Field(default=None, description="If Budget order line, the budget amount.")
    currency_info: Optional[Currency] = None
    end_date: Optional[date] = Field(default=None, description="End date of the order line.")
    estimated_monthly_spend: Optional[Union[StrictFloat, StrictInt]] = Field(default=None, description="If Ongoing (perpetual) order line, the estimated monthly spend")
    last_modified_date_time: Optional[Annotated[str, Field(strict=True)]] = Field(default=None, description="Last modified date.")
    media_contact_email: Optional[StrictStr] = Field(default=None, description="Billing media email")
    media_contact_firstname: Optional[StrictStr] = Field(default=None, description="Billing contact first name")
    media_contact_lastname: Optional[StrictStr] = Field(default=None, description="Billing contact first name")
    order_name: Optional[StrictStr] = Field(default=None, description="The order name")
    pin_order_id: Optional[StrictStr] = Field(default=None, description="The pin order id associated with the order line in SFDC")
    pmp_name: Optional[StrictStr] = Field(default=None, description="The Pinterest marketing partner name")
    po_number: Optional[StrictStr] = Field(default=None, description="The po number")
    salesforce_order_line_id: Optional[StrictStr] = Field(default=None, description="OrderLineId in SFDC")
    start_date: Optional[date] = Field(default=None, description="Start date of the order line.")
    __properties: ClassVar[List[str]] = ["accepted_terms_id", "accepted_terms_time", "ads_manager_order_line_id", "agency_link", "bill_to_company_name", "billing_contact_email", "billing_contact_firstname", "billing_contact_lastname", "budget_amount", "currency_info", "end_date", "estimated_monthly_spend", "last_modified_date_time", "media_contact_email", "media_contact_firstname", "media_contact_lastname", "order_name", "pin_order_id", "pmp_name", "po_number", "salesforce_order_line_id", "start_date"]

    @field_validator('accepted_terms_time')
    def accepted_terms_time_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})T(\d{2}):(\d{2}):(\d{2}).(\d{3})Z$", value):
            raise ValueError(r"must validate the regular expression /^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2}).(\d{3})Z$/")
        return value

    @field_validator('last_modified_date_time')
    def last_modified_date_time_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})T(\d{2}):(\d{2}):(\d{2}).(\d{3})Z$", value):
            raise ValueError(r"must validate the regular expression /^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2}).(\d{3})Z$/")
        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 SSIOOrderLine 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,
        )
        # set to None if accepted_terms_id (nullable) is None
        # and model_fields_set contains the field
        if self.accepted_terms_id is None and "accepted_terms_id" in self.model_fields_set:
            _dict['accepted_terms_id'] = None

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        return _dict

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

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

        _obj = cls.model_validate({
            "accepted_terms_id": obj.get("accepted_terms_id"),
            "accepted_terms_time": obj.get("accepted_terms_time"),
            "ads_manager_order_line_id": obj.get("ads_manager_order_line_id"),
            "agency_link": obj.get("agency_link"),
            "bill_to_company_name": obj.get("bill_to_company_name"),
            "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"),
            "currency_info": obj.get("currency_info"),
            "end_date": obj.get("end_date"),
            "estimated_monthly_spend": obj.get("estimated_monthly_spend"),
            "last_modified_date_time": obj.get("last_modified_date_time"),
            "media_contact_email": obj.get("media_contact_email"),
            "media_contact_firstname": obj.get("media_contact_firstname"),
            "media_contact_lastname": obj.get("media_contact_lastname"),
            "order_name": obj.get("order_name"),
            "pin_order_id": obj.get("pin_order_id"),
            "pmp_name": obj.get("pmp_name"),
            "po_number": obj.get("po_number"),
            "salesforce_order_line_id": obj.get("salesforce_order_line_id"),
            "start_date": obj.get("start_date")
        })
        return _obj


