# 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, field_validator
from typing import Any, ClassVar, Dict, List, Optional
from typing_extensions import Annotated
from cdp.openapi_client.models.evm_swaps_network import EvmSwapsNetwork
from typing import Optional, Set
from typing_extensions import Self

class CreateEvmSwapQuoteRequest(BaseModel):
    """
    CreateEvmSwapQuoteRequest
    """ # noqa: E501
    network: EvmSwapsNetwork
    to_token: Annotated[str, Field(strict=True)] = Field(description="The 0x-prefixed contract address of the token to receive.", alias="toToken")
    from_token: Annotated[str, Field(strict=True)] = Field(description="The 0x-prefixed contract address of the token to send.", alias="fromToken")
    from_amount: Annotated[str, Field(strict=True)] = Field(description="The amount of the `fromToken` to send in atomic units of the token. For example, `1000000000000000000` when sending ETH equates to 1 ETH, `1000000` when sending USDC equates to 1 USDC, etc.", alias="fromAmount")
    taker: Annotated[str, Field(strict=True)] = Field(description="The 0x-prefixed address that holds the `fromToken` balance and has the `Permit2` allowance set for the swap.")
    signer_address: Optional[Annotated[str, Field(strict=True)]] = Field(default=None, description="The 0x-prefixed Externally Owned Account (EOA) address that will sign the `Permit2` EIP-712 permit message. This is only needed if `taker` is a smart contract.", alias="signerAddress")
    gas_price: Optional[Annotated[str, Field(strict=True)]] = Field(default=None, description="The target gas price for the swap transaction, in Wei. For EIP-1559 transactions, this value should be seen as the `maxFeePerGas` value. If not provided, the API will use an estimate based on the current network conditions.", alias="gasPrice")
    slippage_bps: Optional[Annotated[int, Field(le=10000, strict=True, ge=0)]] = Field(default=100, description="The maximum acceptable slippage of the `toToken` in basis points. If this parameter is set to 0, no slippage will be tolerated. If not provided, the default slippage tolerance is 100 bps (i.e., 1%).", alias="slippageBps")
    __properties: ClassVar[List[str]] = ["network", "toToken", "fromToken", "fromAmount", "taker", "signerAddress", "gasPrice", "slippageBps"]

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

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

    @field_validator('from_amount')
    def from_amount_validate_regular_expression(cls, value):
        """Validates the regular expression"""
        if not re.match(r"^\d+$", value):
            raise ValueError(r"must validate the regular expression /^\d+$/")
        return value

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

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

        if not re.match(r"^0x[a-fA-F0-9]{40}$", value):
            raise ValueError(r"must validate the regular expression /^0x[a-fA-F0-9]{40}$/")
        return value

    @field_validator('gas_price')
    def gas_price_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 CreateEvmSwapQuoteRequest 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 CreateEvmSwapQuoteRequest from a dict"""
        if obj is None:
            return None

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

        _obj = cls.model_validate({
            "network": obj.get("network"),
            "toToken": obj.get("toToken"),
            "fromToken": obj.get("fromToken"),
            "fromAmount": obj.get("fromAmount"),
            "taker": obj.get("taker"),
            "signerAddress": obj.get("signerAddress"),
            "gasPrice": obj.get("gasPrice"),
            "slippageBps": obj.get("slippageBps") if obj.get("slippageBps") is not None else 100
        })
        return _obj


