from __future__ import annotations

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

from attrs import define as _attrs_define
from attrs import field as _attrs_field
from dateutil.parser import isoparse

from .. import types
from ..types import UNSET, Unset

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


@_attrs_define
class RecipeImport:
    """
    Attributes:
        name (str):
        created_at (datetime.datetime):
        storage (int):
        space (int):
        id (int | Unset):
        file_uid (str | Unset):
        file_path (str | Unset):
    """

    name: str
    created_at: datetime.datetime
    storage: int
    space: int
    id: int | Unset = UNSET
    file_uid: str | Unset = UNSET
    file_path: str | Unset = UNSET
    additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict)

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

        created_at = self.created_at.isoformat()

        storage = self.storage

        space = self.space

        id = self.id

        file_uid = self.file_uid

        file_path = self.file_path

        field_dict: dict[str, Any] = {}
        field_dict.update(self.additional_properties)
        field_dict.update(
            {
                "name": name,
                "created_at": created_at,
                "storage": storage,
                "space": space,
            }
        )
        if id is not UNSET:
            field_dict["id"] = id
        if file_uid is not UNSET:
            field_dict["file_uid"] = file_uid
        if file_path is not UNSET:
            field_dict["file_path"] = file_path

        return field_dict

    def to_multipart(self) -> types.RequestFiles:
        files: types.RequestFiles = []

        files.append(("name", (None, str(self.name).encode(), "text/plain")))

        files.append(("created_at", (None, self.created_at.isoformat().encode(), "text/plain")))

        files.append(("storage", (None, str(self.storage).encode(), "text/plain")))

        files.append(("space", (None, str(self.space).encode(), "text/plain")))

        if not isinstance(self.id, Unset):
            files.append(("id", (None, str(self.id).encode(), "text/plain")))

        if not isinstance(self.file_uid, Unset):
            files.append(("file_uid", (None, str(self.file_uid).encode(), "text/plain")))

        if not isinstance(self.file_path, Unset):
            files.append(("file_path", (None, str(self.file_path).encode(), "text/plain")))

        for prop_name, prop in self.additional_properties.items():
            files.append((prop_name, (None, str(prop).encode(), "text/plain")))

        return files

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

        created_at = isoparse(d.pop("created_at"))

        storage = d.pop("storage")

        space = d.pop("space")

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

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

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

        recipe_import = cls(
            name=name,
            created_at=created_at,
            storage=storage,
            space=space,
            id=id,
            file_uid=file_uid,
            file_path=file_path,
        )

        recipe_import.additional_properties = d
        return recipe_import

    @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
