from fastapi import APIRouter, HTTPException, status, Depends
from app.schemas import LikeResponse
from app.services.like_service import LikeService
from app.auth import get_current_user

router = APIRouter(prefix="/likes", tags=["likes"])

@router.post("/{liked_user_id}", response_model=LikeResponse)
def like_user(
    liked_user_id: int,
    current_user: dict = Depends(get_current_user)
):
    """Like another user"""
    try:
        return LikeService.like_user(current_user["user_id"], liked_user_id)
    except ValueError as e:
        raise HTTPException(
            status_code=status.HTTP_400_BAD_REQUEST,
            detail=str(e)
        )

@router.delete("/{liked_user_id}")
def unlike_user(
    liked_user_id: int,
    current_user: dict = Depends(get_current_user)
):
    """Unlike another user"""
    return LikeService.unlike_user(current_user["user_id"], liked_user_id)

@router.get("/received/list")
def get_likes_received(current_user: dict = Depends(get_current_user)):
    """Get all likes received (unmatched)"""
    return LikeService.get_likes_received(current_user["user_id"])

@router.get("/matches/list")
def get_matches(current_user: dict = Depends(get_current_user)):
    """Get all matches"""
    return LikeService.get_matches(current_user["user_id"])

@router.post("/received/acknowledge")
def acknowledge_likes(current_user: dict = Depends(get_current_user)):
    """Mark all received likes as acknowledged"""
    return LikeService.acknowledge_likes(current_user["user_id"])

@router.get("/sent/list")
def get_liked_profiles(current_user: dict = Depends(get_current_user)):
    """Get all profiles that current user has liked"""
    return {"liked_ids": LikeService.get_liked_profiles(current_user["user_id"])}
