from __future__ import annotations

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

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

from ..types import UNSET, Unset

if TYPE_CHECKING:
    from ..models.plan import Plan


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


@_attrs_define
class Billing:
    """
    Attributes:
        customer_id (str | Unset):
        plan (Plan | Unset):
        usage (float | Unset):
        scripts (float | Unset):
        activated (bool | Unset):
        reported (float | Unset):
        method (str | Unset):
    """

    customer_id: str | Unset = UNSET
    plan: Plan | Unset = UNSET
    usage: float | Unset = UNSET
    scripts: float | Unset = UNSET
    activated: bool | Unset = UNSET
    reported: float | Unset = UNSET
    method: str | Unset = UNSET
    additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict)

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

        plan: dict[str, Any] | Unset = UNSET
        if not isinstance(self.plan, Unset):
            plan = self.plan.to_dict()

        usage = self.usage

        scripts = self.scripts

        activated = self.activated

        reported = self.reported

        method = self.method

        field_dict: dict[str, Any] = {}
        field_dict.update(self.additional_properties)
        field_dict.update({})
        if customer_id is not UNSET:
            field_dict["customerID"] = customer_id
        if plan is not UNSET:
            field_dict["plan"] = plan
        if usage is not UNSET:
            field_dict["usage"] = usage
        if scripts is not UNSET:
            field_dict["scripts"] = scripts
        if activated is not UNSET:
            field_dict["activated"] = activated
        if reported is not UNSET:
            field_dict["reported"] = reported
        if method is not UNSET:
            field_dict["method"] = method

        return field_dict

    @classmethod
    def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T:
        from ..models.plan import Plan

        d = dict(src_dict)
        customer_id = d.pop("customerID", UNSET)

        _plan = d.pop("plan", UNSET)
        plan: Plan | Unset
        if isinstance(_plan, Unset):
            plan = UNSET
        else:
            plan = Plan.from_dict(_plan)

        usage = d.pop("usage", UNSET)

        scripts = d.pop("scripts", UNSET)

        activated = d.pop("activated", UNSET)

        reported = d.pop("reported", UNSET)

        method = d.pop("method", UNSET)

        billing = cls(
            customer_id=customer_id,
            plan=plan,
            usage=usage,
            scripts=scripts,
            activated=activated,
            reported=reported,
            method=method,
        )

        billing.additional_properties = d
        return billing

    @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
