from datetime import datetime
from typing import Dict, List, Optional

from pydantic import BaseModel, Field


class NextcloudInstanceBase(BaseModel):
    customer_id: int
    base_url: str
    auth_type: str = "basic"
    username: str


class NextcloudInstanceCreate(NextcloudInstanceBase):
    password: str = Field(..., min_length=1)


class NextcloudInstanceUpdate(BaseModel):
    base_url: Optional[str] = None
    auth_type: Optional[str] = None
    username: Optional[str] = None
    password: Optional[str] = None
    is_enabled: Optional[bool] = None


class NextcloudInstance(NextcloudInstanceBase):
    id: int
    is_enabled: bool
    disabled_at: Optional[datetime] = None
    created_at: datetime
    updated_at: datetime


class NextcloudStatus(BaseModel):
    status: str
    checked_at: datetime
    version: Optional[str] = None
    php: Optional[str] = None
    db: Optional[str] = None
    metrics: Dict[str, Optional[str]] = {}


class NextcloudUserCreate(BaseModel):
    uid: str
    display_name: Optional[str] = None
    email: Optional[str] = None
    groups: List[str] = []
    send_welcome: bool = True


class NextcloudPasswordReset(BaseModel):
    send_email: bool = True


class NextcloudAuditLogEntry(BaseModel):
    id: int
    customer_id: int
    instance_id: Optional[int] = None
    event_type: str
    request_meta: Optional[Dict] = None
    response_meta: Optional[Dict] = None
    actor_user_id: Optional[int] = None
    created_at: datetime
