from __future__ import annotations

from collections.abc import Mapping
from typing import Any, TypeVar, cast

from attrs import define as _attrs_define
from attrs import field as _attrs_field

from ..types import UNSET, Unset

T = TypeVar("T", bound="NetSuiteTBARequest")


@_attrs_define
class NetSuiteTBARequest:
    """Token-Based Authentication (TBA) for NetSuite SuiteTalk (OAuth 1.0):
    - realm == account_id
    - signature method HMAC-SHA256 (used per-request)

        Attributes:
            account_id (str):
            consumer_key (str):
            consumer_secret (str):
            access_token (str):
            token_secret (str):
            base_url (None | str | Unset):
    """

    account_id: str
    consumer_key: str
    consumer_secret: str
    access_token: str
    token_secret: str
    base_url: None | str | Unset = UNSET
    additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict)

    def to_dict(self) -> dict[str, Any]:
        account_id = self.account_id

        consumer_key = self.consumer_key

        consumer_secret = self.consumer_secret

        access_token = self.access_token

        token_secret = self.token_secret

        base_url: None | str | Unset
        if isinstance(self.base_url, Unset):
            base_url = UNSET
        else:
            base_url = self.base_url

        field_dict: dict[str, Any] = {}
        field_dict.update(self.additional_properties)
        field_dict.update(
            {
                "account_id": account_id,
                "consumer_key": consumer_key,
                "consumer_secret": consumer_secret,
                "access_token": access_token,
                "token_secret": token_secret,
            }
        )
        if base_url is not UNSET:
            field_dict["base_url"] = base_url

        return field_dict

    @classmethod
    def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T:
        d = dict(src_dict)
        account_id = d.pop("account_id")

        consumer_key = d.pop("consumer_key")

        consumer_secret = d.pop("consumer_secret")

        access_token = d.pop("access_token")

        token_secret = d.pop("token_secret")

        def _parse_base_url(data: object) -> None | str | Unset:
            if data is None:
                return data
            if isinstance(data, Unset):
                return data
            return cast(None | str | Unset, data)

        base_url = _parse_base_url(d.pop("base_url", UNSET))

        net_suite_tba_request = cls(
            account_id=account_id,
            consumer_key=consumer_key,
            consumer_secret=consumer_secret,
            access_token=access_token,
            token_secret=token_secret,
            base_url=base_url,
        )

        net_suite_tba_request.additional_properties = d
        return net_suite_tba_request

    @property
    def additional_keys(self) -> list[str]:
        return list(self.additional_properties.keys())

    def __getitem__(self, key: str) -> Any:
        return self.additional_properties[key]

    def __setitem__(self, key: str, value: Any) -> None:
        self.additional_properties[key] = value

    def __delitem__(self, key: str) -> None:
        del self.additional_properties[key]

    def __contains__(self, key: str) -> bool:
        return key in self.additional_properties
