from dataclasses import dataclass
from typing import Any, Dict, List, Optional, Union
from datetime import datetime
import dataclasses

@dataclass
class InstancesListOutputItemsProject:
    object: str
    id: str
    status: str
    slug: str
    name: str
    organization_id: str
    magic_mcp_session_duration_minutes: float
    created_at: datetime
    updated_at: datetime
@dataclass
class InstancesListOutputItems:
    object: str
    id: str
    slug: str
    name: str
    organization_id: str
    type: str
    created_at: datetime
    updated_at: datetime
    project: InstancesListOutputItemsProject
@dataclass
class InstancesListOutput:
    object: str
    items: List[InstancesListOutputItems]


class mapInstancesListOutputItemsProject:
    @staticmethod
    def from_dict(data: Dict[str, Any]) -> InstancesListOutputItemsProject:
        return InstancesListOutputItemsProject(
        object=data.get('object'),
        id=data.get('id'),
        status=data.get('status'),
        slug=data.get('slug'),
        name=data.get('name'),
        organization_id=data.get('organization_id'),
        magic_mcp_session_duration_minutes=data.get('magic_mcp_session_duration_minutes'),
        created_at=datetime.fromisoformat(data.get('created_at').replace('Z', '+00:00')) if data.get('created_at') else None,
        updated_at=datetime.fromisoformat(data.get('updated_at').replace('Z', '+00:00')) if data.get('updated_at') else None
        )

    @staticmethod
    def to_dict(value: Union[InstancesListOutputItemsProject, Dict[str, Any], None]) -> Optional[Dict[str, Any]]:
        if value is None:
            return None
        if isinstance(value, dict):
            return value
        return dataclasses.asdict(value)

class mapInstancesListOutputItems:
    @staticmethod
    def from_dict(data: Dict[str, Any]) -> InstancesListOutputItems:
        return InstancesListOutputItems(
        object=data.get('object'),
        id=data.get('id'),
        slug=data.get('slug'),
        name=data.get('name'),
        organization_id=data.get('organization_id'),
        type=data.get('type'),
        created_at=datetime.fromisoformat(data.get('created_at').replace('Z', '+00:00')) if data.get('created_at') else None,
        updated_at=datetime.fromisoformat(data.get('updated_at').replace('Z', '+00:00')) if data.get('updated_at') else None,
        project=mapInstancesListOutputItemsProject.from_dict(data.get('project')) if data.get('project') else None
        )

    @staticmethod
    def to_dict(value: Union[InstancesListOutputItems, Dict[str, Any], None]) -> Optional[Dict[str, Any]]:
        if value is None:
            return None
        if isinstance(value, dict):
            return value
        return dataclasses.asdict(value)

class mapInstancesListOutput:
    @staticmethod
    def from_dict(data: Dict[str, Any]) -> InstancesListOutput:
        return InstancesListOutput(
        object=data.get('object'),
        items=[mapInstancesListOutputItems.from_dict(item) for item in data.get('items', []) if item]
        )

    @staticmethod
    def to_dict(value: Union[InstancesListOutput, Dict[str, Any], None]) -> Optional[Dict[str, Any]]:
        if value is None:
            return None
        if isinstance(value, dict):
            return value
        # assume dataclass for generated models
        return dataclasses.asdict(value)

