# coding: utf-8

"""
    Mixpeek API

    This is the Mixpeek API, providing access to various endpoints for data processing and retrieval.

    The version of the OpenAPI document: 1.3.0
    Contact: info@mixpeek.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 datetime import datetime
from pydantic import BaseModel, ConfigDict, Field, StrictBool, StrictInt, StrictStr
from typing import Any, ClassVar, Dict, List, Optional
from mixpeek.models.batch_statistics import BatchStatistics
from mixpeek.models.bucket_schema_output import BucketSchemaOutput
from mixpeek.models.storage_statistics import StorageStatistics
from mixpeek.models.task_status_enum import TaskStatusEnum
from mixpeek.models.unique_key_config import UniqueKeyConfig
from typing import Optional, Set
from typing_extensions import Self

class BucketResponse(BaseModel):
    """
    Response model for bucket operations.
    """ # noqa: E501
    bucket_id: Optional[StrictStr] = Field(default=None, description="Unique identifier for the bucket")
    bucket_name: StrictStr = Field(description="Human-readable name for the bucket")
    description: Optional[StrictStr] = Field(default=None, description="Description of the bucket")
    bucket_schema: Optional[BucketSchemaOutput] = Field(default=None, description="Schema definition for objects in this bucket")
    unique_key: Optional[UniqueKeyConfig] = Field(default=None, description="Unique key configuration for this bucket (if configured)")
    metadata: Optional[Dict[str, Any]] = Field(default=None, description="Additional metadata for the bucket")
    object_count: StrictInt = Field(description="Number of objects in the bucket")
    total_size_bytes: StrictInt = Field(description="Total size of all objects in the bucket in bytes")
    created_at: Optional[datetime] = Field(default=None, description="When the bucket was created")
    updated_at: Optional[datetime] = Field(default=None, description="Last modification time of bucket metadata")
    last_upload_at: Optional[datetime] = Field(default=None, description="When the last object was uploaded to this bucket")
    status: Optional[TaskStatusEnum] = Field(default=None, description="Bucket lifecycle status (ACTIVE, ARCHIVED, SUSPENDED, IN_PROGRESS for deleting)")
    is_locked: Optional[StrictBool] = Field(default=False, description="Whether the bucket is locked (read-only)")
    batch_stats: Optional[BatchStatistics] = Field(default=None, description="Batch statistics for this bucket (calculated asynchronously, stored in DB)")
    storage_stats: Optional[StorageStatistics] = Field(default=None, description="Storage statistics for this bucket (calculated asynchronously, stored in DB)")
    __properties: ClassVar[List[str]] = ["bucket_id", "bucket_name", "description", "bucket_schema", "unique_key", "metadata", "object_count", "total_size_bytes", "created_at", "updated_at", "last_upload_at", "status", "is_locked", "batch_stats", "storage_stats"]

    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 BucketResponse 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,
        )
        # override the default output from pydantic by calling `to_dict()` of bucket_schema
        if self.bucket_schema:
            _dict['bucket_schema'] = self.bucket_schema.to_dict()
        # override the default output from pydantic by calling `to_dict()` of unique_key
        if self.unique_key:
            _dict['unique_key'] = self.unique_key.to_dict()
        # override the default output from pydantic by calling `to_dict()` of batch_stats
        if self.batch_stats:
            _dict['batch_stats'] = self.batch_stats.to_dict()
        # override the default output from pydantic by calling `to_dict()` of storage_stats
        if self.storage_stats:
            _dict['storage_stats'] = self.storage_stats.to_dict()
        return _dict

    @classmethod
    def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
        """Create an instance of BucketResponse from a dict"""
        if obj is None:
            return None

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

        _obj = cls.model_validate({
            "bucket_id": obj.get("bucket_id"),
            "bucket_name": obj.get("bucket_name"),
            "description": obj.get("description"),
            "bucket_schema": BucketSchemaOutput.from_dict(obj["bucket_schema"]) if obj.get("bucket_schema") is not None else None,
            "unique_key": UniqueKeyConfig.from_dict(obj["unique_key"]) if obj.get("unique_key") is not None else None,
            "metadata": obj.get("metadata"),
            "object_count": obj.get("object_count"),
            "total_size_bytes": obj.get("total_size_bytes"),
            "created_at": obj.get("created_at"),
            "updated_at": obj.get("updated_at"),
            "last_upload_at": obj.get("last_upload_at"),
            "status": obj.get("status"),
            "is_locked": obj.get("is_locked") if obj.get("is_locked") is not None else False,
            "batch_stats": BatchStatistics.from_dict(obj["batch_stats"]) if obj.get("batch_stats") is not None else None,
            "storage_stats": StorageStatistics.from_dict(obj["storage_stats"]) if obj.get("storage_stats") is not None else None
        })
        return _obj


