package com.example.controller;

import com.example.common.Result;
import com.example.common.config.TokenUtils;
import com.example.entity.Account;
import com.example.service.RecommendationService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * 推荐系统控制器
 */
@RestController
@RequestMapping("/recommendation")
public class RecommendationController {

    @Resource
    private RecommendationService recommendationService;
    
    /**
     * 获取个性化推荐资源
     * @param limit 推荐资源数量，默认为4
     * @return 推荐资源列表
     */
    @GetMapping("/resources")
    public Result getRecommendedResources(@RequestParam(defaultValue = "4") Integer limit) {
        // 获取当前登录用户
        Account currentUser = TokenUtils.getCurrentUser();
        if (currentUser == null) {
            return Result.error("401", "用户未登录");
        }
        
        // 验证用户是否为患者
        if (!"patient".equals(currentUser.getRole())) {
            return Result.error("403", "只有患者才能获取个性化推荐");
        }
        
        // 获取推荐资源
        List<Map<String, Object>> recommendations = 
            recommendationService.getRecommendationsForUser(currentUser.getId(), limit);
        
        return Result.success(recommendations);
    }
} 