from fastapi import APIRouter, Depends
from sqlalchemy.orm import Session

from app.core.database import get_db
from app.models.user import User
from app.schemas.common import ResponseModel
from app.services import watermark_service
from app.api.deps import get_current_user

router = APIRouter()


@router.post("/trace")
def trace_watermark(
    req: dict,
    db: Session = Depends(get_db),
    current_user: User = Depends(get_current_user),
):
    text = req.get("text", "")
    result = watermark_service.trace_watermark(db, text)
    if not result:
        return ResponseModel(data=None, message="未检测到水印")
    return ResponseModel(data=result)
