"""vikdata-sdk: Python SDK for vikdata API - IAM, RBAC, and API management platform.

This SDK provides comprehensive access to the vikdata REST API for authentication,
user management, role-based access control (RBAC), API key management, and tenant operations.

Core Features:
- Authentication (login, refresh, logout)
- User role and permission management
- Role CRUD with permission assignment
- API key management with role-based permissions
- Multi-tenant administration
- Automatic retry logic with exponential backoff
- Type-safe request/response models with Pydantic

Basic Usage:
    from vikdata import VikdataClient

    # Initialize client with API key
    async with VikdataClient(
        base_url="https://api.vikdata.com",
        api_key="vk_live_...",
    ) as client:
        # Get current user
        user = await client.auth.me()
        print(user.email, user.permissions)

        # List roles
        roles = await client.roles.list()
        for role in roles.data:
            print(role.name, role.permissions)

Authentication Flow:
    async with VikdataClient(base_url="https://api.vikdata.com") as client:
        # Login with email/password
        tokens = await client.auth.login(
            email="user@example.com",
            password="secret123"
        )

        # Access token is automatically set on client
        user = await client.auth.me()

        # Refresh token when needed
        new_token = await client.auth.refresh(tokens.refresh_token)

        # Logout
        await client.auth.logout()

Role Management:
    # Create a role
    role = await client.roles.create(
        name="Data Analyst",
        slug="data-analyst",
        description="Can read and analyze data",
        permission_ids=[permission_id1, permission_id2]
    )

    # Assign role to user
    assignment = await client.users.assign_role(user_id, role.id)

    # Get user permissions
    permissions = await client.users.get_permissions(user_id)

API Key Management:
    # Create API key with roles
    api_key = await client.api_keys.create(
        name="Production API Key",
        role_ids=[role_id1, role_id2],
        description="For production application",
        expires_at=datetime(2025, 12, 31)
    )

    # Store the key securely - it's only shown once!
    print(api_key.key)  # vk_live_xxxxxxxxxxxxx

    # Rotate key
    new_key = await client.api_keys.rotate(api_key.id)
"""

from vikdata.client import VikdataClient
from vikdata.config import VikdataConfig
from vikdata.exceptions import (
    APIError,
    AuthenticationError,
    AuthorizationError,
    ConflictError,
    HealthCheckError,
    NetworkError,
    RateLimitError,
    ResourceNotFoundError,
    ServerError,
    ServiceRegistrationError,
    TimeoutError,
    ValidationError,
    VikdataError,
)
from vikdata.health import HealthChecker, HealthReporter, check_vikdata_health, wait_for_vikdata
from vikdata.models import (
    HealthStatus,
    HeartbeatResponse,
    Service,
    ServiceHealth,
    ServiceRegistration,
    UsageMetric,
    UsageMetrics,
    UsageReport,
    UsageReportRequest,
    UsageReportResponse,
    UsageStats,
)
from vikdata.types import PaginatedResponse, TokenClaims
from vikdata.usage import UsageReporter

# Core exports
__all__ = [
    # Client
    "VikdataClient",
    "VikdataConfig",
    # Types
    "TokenClaims",
    "PaginatedResponse",
    # Models
    "HealthStatus",
    "HeartbeatResponse",
    "Service",
    "ServiceHealth",
    "ServiceRegistration",
    "UsageMetric",
    "UsageMetrics",
    "UsageReport",
    "UsageReportRequest",
    "UsageReportResponse",
    "UsageStats",
    # Health monitoring
    "HealthChecker",
    "HealthReporter",
    "check_vikdata_health",
    "wait_for_vikdata",
    # Usage tracking
    "UsageReporter",
    # Exceptions
    "VikdataError",
    "AuthenticationError",
    "AuthorizationError",
    "NetworkError",
    "RateLimitError",
    "ValidationError",
    "ServiceRegistrationError",
    "HealthCheckError",
    "ResourceNotFoundError",
    "ConflictError",
    "ServerError",
    "TimeoutError",
    "APIError",
]

# Try to import FastAPI components (optional dependency)
try:
    from vikdata.decorators import ServiceManager, vikdata_service
    from vikdata.middleware import (
        JWTValidationMiddleware,
        UsageMiddleware,
        VikdataMiddleware,
    )

    __all__.extend(
        [
            # Middleware
            "JWTValidationMiddleware",
            "UsageMiddleware",
            "VikdataMiddleware",
            # Decorators
            "vikdata_service",
            "ServiceManager",
        ]
    )
except ImportError:
    # FastAPI not installed - middleware/decorators not available
    pass

__version__ = "0.1.0"
