package com.ruoyi.web.controller.client;


import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.entity.MusicInfo;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.system.service.IBannerInfoService;
import com.ruoyi.system.service.ICategoryInfoService;
import com.ruoyi.system.service.IMusicInfoService;
import com.ruoyi.system.service.IRecommendInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RequestMapping("/client/index")
@RestController
public class IndexController extends BaseController {

    @Autowired
    private IBannerInfoService bannerInfoService;
    @Autowired
    private ICategoryInfoService categoryInfoService;
    @Autowired
    private IMusicInfoService musicInfoService;
    @Autowired
    private IRecommendInfoService recommendInfoService;

    /**
     * @return com.ruoyi.common.core.domain.AjaxResult
     * 获取banner
     */
    @RequestMapping("/getBanner")
    public AjaxResult getBanner(){
        return AjaxResult.success(bannerInfoService.getEnableBanner());
    }

    // 获取分类
    @GetMapping("/getCategory")
    public AjaxResult getCategory(){
        return AjaxResult.success(categoryInfoService.getCategory());
    }

    // 根据分类获取分类音乐
    @GetMapping("/cate/music/{categoryId}")
    public TableDataInfo getCategoryMusic(@PathVariable String categoryId){
        startPage();
        List<MusicInfo> list = musicInfoService.selectMusicInfoByCid(categoryId);
        return getDataTableData(list);
    }

    @GetMapping("/re/music")
    // 获取推荐音乐
    public TableDataInfo getRecommendMusic(){
        startPage();
        List<MusicInfo> list = recommendInfoService.findRecommendMusic();
        return getDataTableData(list);
    }

    @GetMapping("/re/bind/music")
    // 获取推荐绑定音乐
    public AjaxResult getRecommendBindMusic(){
        return AjaxResult.success(recommendInfoService.findRecommendBindMusic());
    }

    @GetMapping("/re/music/{reId}")
    // 获取推荐音乐
    public TableDataInfo getRecommendMusicByReId(@PathVariable String reId){
        startPage();
        List<MusicInfo> list = recommendInfoService.findRecommendMusicByReId(reId);
        return getDataTableData(list);
    }


}
