# 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 ringer_business.models.link import Link
from typing import Optional, Set
from typing_extensions import Self

class CreditCardResponse(BaseModel):
    """
    Detailed information about a stored credit card (excluding sensitive full PAN).
    """ # noqa: E501
    id: StrictInt = Field(description="Unique identifier for the credit card record.")
    name: StrictStr = Field(description="A custom name or label for the credit card (e.g., \"Work Visa\", \"Personal Amex\").")
    last4: StrictStr = Field(description="The last four digits of the credit card number.")
    brand: StrictStr = Field(description="The brand of the credit card (e.g., Visa, Mastercard, American Express).")
    exp_month: StrictInt = Field(description="The expiration month of the credit card (1-12).")
    exp_year: StrictInt = Field(description="The expiration year of the credit card (e.g., 2025).")
    priority: Annotated[int, Field(le=100, strict=True, ge=0)] = Field(description="Priority for payment processing (higher numbers typically processed first). Range 0-100.")
    active: StrictBool = Field(description="Indicates if the card is active for payments.")
    verified: StrictBool = Field(description="Indicates if the card has been successfully verified.")
    expired: StrictBool = Field(description="Indicates if the card is currently expired based on its expiration date.")
    links: Optional[List[Link]] = Field(default=None, description="HATEOAS links related to this credit card.")
    __properties: ClassVar[List[str]] = ["id", "name", "last4", "brand", "exp_month", "exp_year", "priority", "active", "verified", "expired", "links"]

    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 CreditCardResponse 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.
        * OpenAPI `readOnly` fields are excluded.
        """
        excluded_fields: Set[str] = set([
            "expired",
        ])

        _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 links (list)
        _items = []
        if self.links:
            for _item_links in self.links:
                if _item_links:
                    _items.append(_item_links.to_dict())
            _dict['links'] = _items
        # set to None if links (nullable) is None
        # and model_fields_set contains the field
        if self.links is None and "links" in self.model_fields_set:
            _dict['links'] = None

        return _dict

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

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

        _obj = cls.model_validate({
            "id": obj.get("id"),
            "name": obj.get("name"),
            "last4": obj.get("last4"),
            "brand": obj.get("brand"),
            "exp_month": obj.get("exp_month"),
            "exp_year": obj.get("exp_year"),
            "priority": obj.get("priority"),
            "active": obj.get("active"),
            "verified": obj.get("verified"),
            "expired": obj.get("expired"),
            "links": [Link.from_dict(_item) for _item in obj["links"]] if obj.get("links") is not None else None
        })
        return _obj


