# coding: utf-8

"""
    Coinbase Developer Platform APIs

    The Coinbase Developer Platform APIs - leading the world's transition onchain.

    The version of the OpenAPI document: 2.0.0
    Contact: cdp@coinbase.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, StrictInt, StrictStr, field_validator
from typing import Any, ClassVar, Dict, List, Optional
from typing_extensions import Annotated
from typing import Optional, Set
from typing_extensions import Self

class X402PaymentRequirements(BaseModel):
    """
    The x402 protocol payment requirements that the resource server expects the client's payment payload to meet.
    """ # noqa: E501
    scheme: StrictStr = Field(description="The scheme of the payment protocol to use. Currently, the only supported scheme is `exact`.")
    network: StrictStr = Field(description="The network of the blockchain to send payment on.")
    max_amount_required: StrictStr = Field(description="The maximum amount required to pay for the resource in atomic units of the payment asset.", alias="maxAmountRequired")
    resource: StrictStr = Field(description="The URL of the resource to pay for.")
    description: StrictStr = Field(description="The description of the resource.")
    mime_type: StrictStr = Field(description="The MIME type of the resource response.", alias="mimeType")
    output_schema: Optional[Dict[str, Any]] = Field(default=None, description="The optional JSON schema describing the resource output.", alias="outputSchema")
    pay_to: Annotated[str, Field(strict=True)] = Field(description="The destination to pay value to.  For EVM networks, payTo will be a 0x-prefixed, checksum EVM address.  For Solana-based networks, payTo will be a base58-encoded Solana address.", alias="payTo")
    max_timeout_seconds: StrictInt = Field(description="The maximum time in seconds for the resource server to respond.", alias="maxTimeoutSeconds")
    asset: Annotated[str, Field(strict=True)] = Field(description="The asset to pay with.  For EVM networks, the asset will be a 0x-prefixed, checksum EVM address.  For Solana-based networks, the asset will be a base58-encoded Solana address.")
    extra: Optional[Dict[str, Any]] = Field(default=None, description="The optional additional scheme-specific payment info.")
    __properties: ClassVar[List[str]] = ["scheme", "network", "maxAmountRequired", "resource", "description", "mimeType", "outputSchema", "payTo", "maxTimeoutSeconds", "asset", "extra"]

    @field_validator('scheme')
    def scheme_validate_enum(cls, value):
        """Validates the enum"""
        if value not in set(['exact']):
            raise ValueError("must be one of enum values ('exact')")
        return value

    @field_validator('network')
    def network_validate_enum(cls, value):
        """Validates the enum"""
        if value not in set(['base-sepolia', 'base', 'solana-devnet', 'solana']):
            raise ValueError("must be one of enum values ('base-sepolia', 'base', 'solana-devnet', 'solana')")
        return value

    @field_validator('pay_to')
    def pay_to_validate_regular_expression(cls, value):
        """Validates the regular expression"""
        if not re.match(r"^0x[a-fA-F0-9]{40}|[A-Za-z0-9][A-Za-z0-9-]{0,34}[A-Za-z0-9]$", value):
            raise ValueError(r"must validate the regular expression /^0x[a-fA-F0-9]{40}|[A-Za-z0-9][A-Za-z0-9-]{0,34}[A-Za-z0-9]$/")
        return value

    @field_validator('asset')
    def asset_validate_regular_expression(cls, value):
        """Validates the regular expression"""
        if not re.match(r"^0x[a-fA-F0-9]{40}|[A-Za-z0-9][A-Za-z0-9-]{0,34}[A-Za-z0-9]$", value):
            raise ValueError(r"must validate the regular expression /^0x[a-fA-F0-9]{40}|[A-Za-z0-9][A-Za-z0-9-]{0,34}[A-Za-z0-9]$/")
        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 X402PaymentRequirements 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,
        )
        return _dict

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

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

        _obj = cls.model_validate({
            "scheme": obj.get("scheme"),
            "network": obj.get("network"),
            "maxAmountRequired": obj.get("maxAmountRequired"),
            "resource": obj.get("resource"),
            "description": obj.get("description"),
            "mimeType": obj.get("mimeType"),
            "outputSchema": obj.get("outputSchema"),
            "payTo": obj.get("payTo"),
            "maxTimeoutSeconds": obj.get("maxTimeoutSeconds"),
            "asset": obj.get("asset"),
            "extra": obj.get("extra")
        })
        return _obj


