# 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.order_line_paid_type import OrderLinePaidType
from pinterestsdk.models.order_line_status import OrderLineStatus
from typing import Optional, Set
from typing_extensions import Self

class OrderLine(BaseModel):
    """
    OrderLine
    """ # noqa: E501
    ad_account_id: Optional[StrictStr] = Field(default=None, description="Ad account ID.")
    budget: Optional[Union[StrictFloat, StrictInt]] = Field(default=None, description="Order line budget in micro currency.")
    end_time: Optional[Union[StrictFloat, StrictInt]] = Field(default=None, description="End time. Unix timestamp.")
    id: Optional[Annotated[str, Field(strict=True)]] = Field(default=None, description="Order line ID.")
    name: Optional[StrictStr] = Field(default=None, description="Order line name.")
    paid_budget: Optional[Union[StrictFloat, StrictInt]] = Field(default=None, description="Order line paid budget in micro currency.")
    paid_type: Optional[OrderLinePaidType] = Field(default=None, description="Order line paid type.")
    purchase_order_id: Optional[StrictStr] = Field(default=None, description="Purchase order ID.")
    start_time: Optional[Union[StrictFloat, StrictInt]] = Field(default=None, description="Start time. Unix timestamp.")
    status: Optional[OrderLineStatus] = Field(default=None, description="Order line status.")
    type: Optional[StrictStr] = Field(default=None, description="Always \"orderline\".")
    campaign_ids: List[StrictStr] = Field(description="Associated List of campaign IDs.")
    __properties: ClassVar[List[str]] = ["ad_account_id", "budget", "end_time", "id", "name", "paid_budget", "paid_type", "purchase_order_id", "start_time", "status", "type", "campaign_ids"]

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

        if not re.match(r"^\d+$", value):
            raise ValueError(r"must validate the regular expression /^\d+$/")
        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 OrderLine 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 budget (nullable) is None
        # and model_fields_set contains the field
        if self.budget is None and "budget" in self.model_fields_set:
            _dict['budget'] = None

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

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

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

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

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

        return _dict

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

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

        _obj = cls.model_validate({
            "ad_account_id": obj.get("ad_account_id"),
            "budget": obj.get("budget"),
            "end_time": obj.get("end_time"),
            "id": obj.get("id"),
            "name": obj.get("name"),
            "paid_budget": obj.get("paid_budget"),
            "paid_type": obj.get("paid_type"),
            "purchase_order_id": obj.get("purchase_order_id"),
            "start_time": obj.get("start_time"),
            "status": obj.get("status"),
            "type": obj.get("type"),
            "campaign_ids": obj.get("campaign_ids")
        })
        return _obj


