# coding: utf-8

"""
    Ringer Business API - Credit Card Management

    This API provides endpoints for managing credit card payment methods associated with a customer account. It allows developers to: - List existing credit cards. - Add a new credit card. - Retrieve details of a specific credit card. - Update information for an existing credit card. - Delete a credit card. - Verify a newly added credit card.  Proper security and PCI compliance considerations are paramount when handling credit card data. These endpoints are designed to interact with a secure payment processing backend. 

    The version of the OpenAPI document: 1.0.0
    Contact: support@ringer.tel
    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, StrictBool, StrictInt, StrictStr
from typing import Any, ClassVar, Dict, List, Optional
from typing_extensions import Annotated
from typing import Optional, Set
from typing_extensions import Self

class CreditCardCreateRequest(BaseModel):
    """
    Information required to add and tokenize a new credit card.
    """ # noqa: E501
    name: StrictStr = Field(description="A custom name for the credit card.")
    card_number: StrictStr = Field(description="The full credit card number (PAN). This will be tokenized and not stored directly by Ringer.")
    exp_month: Annotated[int, Field(le=12, strict=True, ge=1)] = Field(description="Expiration month (1-12).")
    exp_year: StrictInt = Field(description="Expiration year (e.g., 2026). Future year expected.")
    cvv: StrictStr = Field(description="The 3 or 4-digit card verification value (CVV/CVC).")
    first_name: StrictStr = Field(description="Cardholder's first name.")
    last_name: StrictStr = Field(description="Cardholder's last name.")
    address_line1: StrictStr = Field(description="Cardholder's billing address - street line 1.")
    address_line2: Optional[StrictStr] = Field(default=None, description="Cardholder's billing address - street line 2 (e.g., apartment, suite).")
    city: StrictStr = Field(description="Cardholder's billing address - city.")
    state_province: Optional[StrictStr] = Field(default=None, description="Cardholder's billing address - state or province code.")
    postal_code: StrictStr = Field(description="Cardholder's billing address - postal or ZIP code.")
    country: StrictStr = Field(description="Cardholder's billing address - two-letter ISO 3166-1 alpha-2 country code.")
    priority: Optional[Annotated[int, Field(le=100, strict=True, ge=0)]] = Field(default=50, description="Payment priority (0-100). Higher values are typically tried first.")
    active: Optional[StrictBool] = Field(default=True, description="Set whether this card should be active for payments upon creation.")
    __properties: ClassVar[List[str]] = ["name", "card_number", "exp_month", "exp_year", "cvv", "first_name", "last_name", "address_line1", "address_line2", "city", "state_province", "postal_code", "country", "priority", "active"]

    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 CreditCardCreateRequest 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 address_line2 (nullable) is None
        # and model_fields_set contains the field
        if self.address_line2 is None and "address_line2" in self.model_fields_set:
            _dict['address_line2'] = None

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

        return _dict

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

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

        _obj = cls.model_validate({
            "name": obj.get("name"),
            "card_number": obj.get("card_number"),
            "exp_month": obj.get("exp_month"),
            "exp_year": obj.get("exp_year"),
            "cvv": obj.get("cvv"),
            "first_name": obj.get("first_name"),
            "last_name": obj.get("last_name"),
            "address_line1": obj.get("address_line1"),
            "address_line2": obj.get("address_line2"),
            "city": obj.get("city"),
            "state_province": obj.get("state_province"),
            "postal_code": obj.get("postal_code"),
            "country": obj.get("country"),
            "priority": obj.get("priority") if obj.get("priority") is not None else 50,
            "active": obj.get("active") if obj.get("active") is not None else True
        })
        return _obj


