"""
API Schemas for Demo Session Service
"""

from pydantic import BaseModel, Field
from typing import Optional, Dict, Any
from datetime import datetime


class DemoSessionCreate(BaseModel):
    """Create demo session request"""
    demo_account_type: str = Field(..., description="professional or enterprise")
    subscription_tier: Optional[str] = Field(None, description="Force specific subscription tier (professional/enterprise)")
    user_id: Optional[str] = Field(None, description="Optional authenticated user ID")
    ip_address: Optional[str] = None
    user_agent: Optional[str] = None


class DemoUser(BaseModel):
    """Demo user data returned in session response"""
    id: str
    email: str
    full_name: str
    role: str
    is_active: bool
    is_verified: bool
    tenant_id: str
    created_at: str


class DemoTenant(BaseModel):
    """Demo tenant data returned in session response"""
    id: str
    name: str
    subdomain: str
    subscription_tier: str
    tenant_type: str
    business_type: Optional[str] = None
    business_model: Optional[str] = None
    description: Optional[str] = None
    is_active: bool


class DemoSessionResponse(BaseModel):
    """Demo session response - mirrors a real login response with user and tenant data"""
    session_id: str
    virtual_tenant_id: str
    demo_account_type: str
    status: str
    created_at: datetime
    expires_at: datetime
    demo_config: Dict[str, Any]
    session_token: str
    subscription_tier: str
    is_enterprise: bool
    # Complete user and tenant data (like a real login response)
    user: DemoUser
    tenant: DemoTenant

    class Config:
        from_attributes = True


class DemoSessionExtend(BaseModel):
    """Extend session request"""
    session_id: str


class DemoSessionDestroy(BaseModel):
    """Destroy session request"""
    session_id: str


class DemoSessionStats(BaseModel):
    """Demo session statistics"""
    total_sessions: int
    active_sessions: int
    expired_sessions: int
    destroyed_sessions: int
    avg_duration_minutes: float
    total_requests: int


class DemoAccountInfo(BaseModel):
    """Public demo account information"""
    account_type: str
    name: str
    email: str
    password: str
    description: str
    features: list[str]
    business_model: str


class CloneDataRequest(BaseModel):
    """Request to clone tenant data"""
    base_tenant_id: str
    virtual_tenant_id: str
    session_id: str


class CloneDataResponse(BaseModel):
    """Response from data cloning"""
    session_id: str
    services_cloned: list[str]
    total_records: int
    redis_keys: int
