from fastapi import APIRouter, Depends, HTTPException, status
from sqlalchemy.orm import Session
from typing import Dict, Any, List, Optional

from app.core import get_db, get_current_active_user, get_current_admin_user
from app import services
from app.schemas.content_schemas import PageCreate, PageUpdate
from app.models.user_models import User as UserModel

# Роутер для контента
content_router = APIRouter(prefix="/content", tags=["Контент"])

@content_router.post("/pages", response_model=Dict[str, Any])
async def create_page_endpoint(page: PageCreate, current_user: UserModel = Depends(get_current_admin_user), db: Session = Depends(get_db)):
    return services.create_page(db, page)


@content_router.put("/pages/{page_id}", response_model=Dict[str, Any])
async def update_page_endpoint(page_id: int, page: PageUpdate, current_user: UserModel = Depends(get_current_admin_user), db: Session = Depends(get_db)):
    return services.update_page(db, page_id, page)


@content_router.delete("/pages/{page_id}", response_model=Dict[str, Any])
async def delete_page_endpoint(page_id: int, current_user: UserModel = Depends(get_current_admin_user), db: Session = Depends(get_db)):
    return services.delete_page(db, page_id)


@content_router.get("/pages/{page_id}", response_model=Dict[str, Any])
async def get_page_endpoint(page_id: int, db: Session = Depends(get_db)):
    return services.get_page(db, page_id)


@content_router.get("/pages/slug/{slug}", response_model=Dict[str, Any])
async def get_page_by_slug_endpoint(slug: str, db: Session = Depends(get_db)):
    return services.get_page_by_slug(db, slug)


@content_router.get("/pages", response_model=Dict[str, Any])
async def get_pages_endpoint(skip: int = 0, limit: int = 10, db: Session = Depends(get_db)):
    return services.get_pages(db, skip, limit) 