from __future__ import annotations

from collections.abc import Mapping
from typing import Any, TypeVar, BinaryIO, TextIO, TYPE_CHECKING, Generator

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

from ..types import UNSET, Unset

from ..types import UNSET, Unset
from dateutil.parser import isoparse
from typing import cast
import datetime

if TYPE_CHECKING:
  from ..models.bucket_file import BucketFile





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



@_attrs_define
class BucketDetailResponse:
    """ 
        Attributes:
            id (str):
            name (str):
            owner (str):
            files (list[BucketFile]):
            description (None | str | Unset):
            created_at (datetime.datetime | Unset):
            expires_at (datetime.datetime | None | Unset):
            last_used_at (datetime.datetime | None | Unset):
            file_count (int | str | Unset):
            total_size (int | str | Unset):
            has_more_files (bool | Unset):
     """

    id: str
    name: str
    owner: str
    files: list[BucketFile]
    description: None | str | Unset = UNSET
    created_at: datetime.datetime | Unset = UNSET
    expires_at: datetime.datetime | None | Unset = UNSET
    last_used_at: datetime.datetime | None | Unset = UNSET
    file_count: int | str | Unset = UNSET
    total_size: int | str | Unset = UNSET
    has_more_files: bool | Unset = UNSET
    additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict)





    def to_dict(self) -> dict[str, Any]:
        from ..models.bucket_file import BucketFile
        id = self.id

        name = self.name

        owner = self.owner

        files = []
        for files_item_data in self.files:
            files_item = files_item_data.to_dict()
            files.append(files_item)



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

        created_at: str | Unset = UNSET
        if not isinstance(self.created_at, Unset):
            created_at = self.created_at.isoformat()

        expires_at: None | str | Unset
        if isinstance(self.expires_at, Unset):
            expires_at = UNSET
        elif isinstance(self.expires_at, datetime.datetime):
            expires_at = self.expires_at.isoformat()
        else:
            expires_at = self.expires_at

        last_used_at: None | str | Unset
        if isinstance(self.last_used_at, Unset):
            last_used_at = UNSET
        elif isinstance(self.last_used_at, datetime.datetime):
            last_used_at = self.last_used_at.isoformat()
        else:
            last_used_at = self.last_used_at

        file_count: int | str | Unset
        if isinstance(self.file_count, Unset):
            file_count = UNSET
        else:
            file_count = self.file_count

        total_size: int | str | Unset
        if isinstance(self.total_size, Unset):
            total_size = UNSET
        else:
            total_size = self.total_size

        has_more_files = self.has_more_files


        field_dict: dict[str, Any] = {}
        field_dict.update(self.additional_properties)
        field_dict.update({
            "id": id,
            "name": name,
            "owner": owner,
            "files": files,
        })
        if description is not UNSET:
            field_dict["description"] = description
        if created_at is not UNSET:
            field_dict["created_at"] = created_at
        if expires_at is not UNSET:
            field_dict["expires_at"] = expires_at
        if last_used_at is not UNSET:
            field_dict["last_used_at"] = last_used_at
        if file_count is not UNSET:
            field_dict["file_count"] = file_count
        if total_size is not UNSET:
            field_dict["total_size"] = total_size
        if has_more_files is not UNSET:
            field_dict["has_more_files"] = has_more_files

        return field_dict



    @classmethod
    def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T:
        from ..models.bucket_file import BucketFile
        d = dict(src_dict)
        id = d.pop("id")

        name = d.pop("name")

        owner = d.pop("owner")

        files = []
        _files = d.pop("files")
        for files_item_data in (_files):
            files_item = BucketFile.from_dict(files_item_data)



            files.append(files_item)


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

        description = _parse_description(d.pop("description", UNSET))


        _created_at = d.pop("created_at", UNSET)
        created_at: datetime.datetime | Unset
        if isinstance(_created_at,  Unset):
            created_at = UNSET
        else:
            created_at = isoparse(_created_at)




        def _parse_expires_at(data: object) -> datetime.datetime | None | Unset:
            if data is None:
                return data
            if isinstance(data, Unset):
                return data
            try:
                if not isinstance(data, str):
                    raise TypeError()
                expires_at_type_1 = isoparse(data)



                return expires_at_type_1
            except (TypeError, ValueError, AttributeError, KeyError):
                pass
            return cast(datetime.datetime | None | Unset, data)

        expires_at = _parse_expires_at(d.pop("expires_at", UNSET))


        def _parse_last_used_at(data: object) -> datetime.datetime | None | Unset:
            if data is None:
                return data
            if isinstance(data, Unset):
                return data
            try:
                if not isinstance(data, str):
                    raise TypeError()
                last_used_at_type_1 = isoparse(data)



                return last_used_at_type_1
            except (TypeError, ValueError, AttributeError, KeyError):
                pass
            return cast(datetime.datetime | None | Unset, data)

        last_used_at = _parse_last_used_at(d.pop("last_used_at", UNSET))


        def _parse_file_count(data: object) -> int | str | Unset:
            if isinstance(data, Unset):
                return data
            return cast(int | str | Unset, data)

        file_count = _parse_file_count(d.pop("file_count", UNSET))


        def _parse_total_size(data: object) -> int | str | Unset:
            if isinstance(data, Unset):
                return data
            return cast(int | str | Unset, data)

        total_size = _parse_total_size(d.pop("total_size", UNSET))


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

        bucket_detail_response = cls(
            id=id,
            name=name,
            owner=owner,
            files=files,
            description=description,
            created_at=created_at,
            expires_at=expires_at,
            last_used_at=last_used_at,
            file_count=file_count,
            total_size=total_size,
            has_more_files=has_more_files,
        )


        bucket_detail_response.additional_properties = d
        return bucket_detail_response

    @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
