# coding: utf-8

"""
    FlexPrice API

    FlexPrice API Service

    The version of the OpenAPI document: 1.0
    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
from typing import Any, ClassVar, Dict, List, Optional, Union
from typing_extensions import Annotated
from flexprice.models.dto_add_addon_to_subscription_request import DtoAddAddonToSubscriptionRequest
from flexprice.models.dto_create_credit_grant_request import DtoCreateCreditGrantRequest
from flexprice.models.dto_override_line_item_request import DtoOverrideLineItemRequest
from flexprice.models.dto_subscription_schedule_phase_input import DtoSubscriptionSchedulePhaseInput
from flexprice.models.dto_tax_rate_override import DtoTaxRateOverride
from flexprice.models.types_billing_cadence import TypesBillingCadence
from flexprice.models.types_billing_cycle import TypesBillingCycle
from flexprice.models.types_billing_period import TypesBillingPeriod
from flexprice.models.types_collection_method import TypesCollectionMethod
from flexprice.models.types_payment_behavior import TypesPaymentBehavior
from flexprice.models.types_proration_behavior import TypesProrationBehavior
from typing import Optional, Set
from typing_extensions import Self

class DtoCreateSubscriptionRequest(BaseModel):
    """
    DtoCreateSubscriptionRequest
    """ # noqa: E501
    addons: Optional[List[DtoAddAddonToSubscriptionRequest]] = Field(default=None, description="Addons represents addons to be added to the subscription during creation")
    billing_cadence: TypesBillingCadence
    billing_cycle: Optional[TypesBillingCycle] = None
    billing_period: TypesBillingPeriod
    billing_period_count: Annotated[int, Field(strict=True, ge=1)]
    collection_method: Optional[TypesCollectionMethod] = None
    commitment_amount: Optional[Union[StrictFloat, StrictInt]] = Field(default=None, description="CommitmentAmount is the minimum amount a customer commits to paying for a billing period")
    coupons: Optional[List[StrictStr]] = Field(default=None, description="SubscriptionCoupons is a list of coupon IDs to be applied to the subscription")
    credit_grants: Optional[List[DtoCreateCreditGrantRequest]] = Field(default=None, description="Credit grants to be applied when subscription is created")
    currency: StrictStr
    customer_id: Optional[StrictStr] = Field(default=None, description="customer_id is the flexprice customer id and it is prioritized over external_customer_id in case both are provided.")
    customer_timezone: Optional[StrictStr] = Field(default=None, description="Timezone of the customer. If not set, the default value is UTC.")
    end_date: Optional[StrictStr] = None
    external_customer_id: Optional[StrictStr] = Field(default=None, description="external_customer_id is the customer id in your DB and must be same as what you provided as external_id while creating the customer in flexprice.")
    gateway_payment_method_id: Optional[StrictStr] = None
    line_item_coupons: Optional[Dict[str, List[StrictStr]]] = Field(default=None, description="SubscriptionLineItemsCoupons is a list of coupon IDs to be applied to the subscription line items")
    lookup_key: Optional[StrictStr] = None
    metadata: Optional[Dict[str, StrictStr]] = None
    overage_factor: Optional[Union[StrictFloat, StrictInt]] = Field(default=None, description="OverageFactor is a multiplier applied to usage beyond the commitment amount")
    override_line_items: Optional[List[DtoOverrideLineItemRequest]] = Field(default=None, description="OverrideLineItems allows customizing specific prices for this subscription")
    payment_behavior: Optional[TypesPaymentBehavior] = None
    phases: Optional[List[DtoSubscriptionSchedulePhaseInput]] = Field(default=None, description="Phases represents an optional timeline of subscription phases")
    plan_id: StrictStr
    proration_behavior: Optional[TypesProrationBehavior] = None
    start_date: Optional[StrictStr] = None
    tax_rate_overrides: Optional[List[DtoTaxRateOverride]] = Field(default=None, description="tax_rate_overrides is the tax rate overrides to be applied to the subscription")
    trial_end: Optional[StrictStr] = None
    trial_start: Optional[StrictStr] = None
    __properties: ClassVar[List[str]] = ["addons", "billing_cadence", "billing_cycle", "billing_period", "billing_period_count", "collection_method", "commitment_amount", "coupons", "credit_grants", "currency", "customer_id", "customer_timezone", "end_date", "external_customer_id", "gateway_payment_method_id", "line_item_coupons", "lookup_key", "metadata", "overage_factor", "override_line_items", "payment_behavior", "phases", "plan_id", "proration_behavior", "start_date", "tax_rate_overrides", "trial_end", "trial_start"]

    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 DtoCreateSubscriptionRequest 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 each item in addons (list)
        _items = []
        if self.addons:
            for _item_addons in self.addons:
                if _item_addons:
                    _items.append(_item_addons.to_dict())
            _dict['addons'] = _items
        # override the default output from pydantic by calling `to_dict()` of each item in credit_grants (list)
        _items = []
        if self.credit_grants:
            for _item_credit_grants in self.credit_grants:
                if _item_credit_grants:
                    _items.append(_item_credit_grants.to_dict())
            _dict['credit_grants'] = _items
        # override the default output from pydantic by calling `to_dict()` of each item in override_line_items (list)
        _items = []
        if self.override_line_items:
            for _item_override_line_items in self.override_line_items:
                if _item_override_line_items:
                    _items.append(_item_override_line_items.to_dict())
            _dict['override_line_items'] = _items
        # override the default output from pydantic by calling `to_dict()` of each item in phases (list)
        _items = []
        if self.phases:
            for _item_phases in self.phases:
                if _item_phases:
                    _items.append(_item_phases.to_dict())
            _dict['phases'] = _items
        # override the default output from pydantic by calling `to_dict()` of each item in tax_rate_overrides (list)
        _items = []
        if self.tax_rate_overrides:
            for _item_tax_rate_overrides in self.tax_rate_overrides:
                if _item_tax_rate_overrides:
                    _items.append(_item_tax_rate_overrides.to_dict())
            _dict['tax_rate_overrides'] = _items
        return _dict

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

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

        _obj = cls.model_validate({
            "addons": [DtoAddAddonToSubscriptionRequest.from_dict(_item) for _item in obj["addons"]] if obj.get("addons") is not None else None,
            "billing_cadence": obj.get("billing_cadence"),
            "billing_cycle": obj.get("billing_cycle"),
            "billing_period": obj.get("billing_period"),
            "billing_period_count": obj.get("billing_period_count"),
            "collection_method": obj.get("collection_method"),
            "commitment_amount": obj.get("commitment_amount"),
            "coupons": obj.get("coupons"),
            "credit_grants": [DtoCreateCreditGrantRequest.from_dict(_item) for _item in obj["credit_grants"]] if obj.get("credit_grants") is not None else None,
            "currency": obj.get("currency"),
            "customer_id": obj.get("customer_id"),
            "customer_timezone": obj.get("customer_timezone"),
            "end_date": obj.get("end_date"),
            "external_customer_id": obj.get("external_customer_id"),
            "gateway_payment_method_id": obj.get("gateway_payment_method_id"),
            "line_item_coupons": obj.get("line_item_coupons"),
            "lookup_key": obj.get("lookup_key"),
            "metadata": obj.get("metadata"),
            "overage_factor": obj.get("overage_factor"),
            "override_line_items": [DtoOverrideLineItemRequest.from_dict(_item) for _item in obj["override_line_items"]] if obj.get("override_line_items") is not None else None,
            "payment_behavior": obj.get("payment_behavior"),
            "phases": [DtoSubscriptionSchedulePhaseInput.from_dict(_item) for _item in obj["phases"]] if obj.get("phases") is not None else None,
            "plan_id": obj.get("plan_id"),
            "proration_behavior": obj.get("proration_behavior"),
            "start_date": obj.get("start_date"),
            "tax_rate_overrides": [DtoTaxRateOverride.from_dict(_item) for _item in obj["tax_rate_overrides"]] if obj.get("tax_rate_overrides") is not None else None,
            "trial_end": obj.get("trial_end"),
            "trial_start": obj.get("trial_start")
        })
        return _obj


