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.CategoryInfo;
import com.ruoyi.common.core.domain.entity.MusicInfo;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.system.service.IMusicInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RequestMapping("/client/music")
@RestController
public class MusicController extends BaseController {

    @Autowired
    private IMusicInfoService musicService;

    // 根据分类获取音乐
    @RequestMapping("/cate/music")
    public void getMusicByCate(@RequestBody CategoryInfo categoryInfo){
        musicService.findMusicByCate(categoryInfo);
    }


    // 创建歌单
    @RequestMapping("/collect/music/{collectId}")
    public TableDataInfo createPlaylist(@PathVariable String collectId){
        startPage();
        List<MusicInfo> list = musicService.findMusicByCollectId(collectId);
        //musicService.createPlaylist();
        return getDataTableData(list);
    }


    // 添加我喜欢的音乐
    @RequestMapping("/like/music/{musicId}")
    public AjaxResult addLikeMusic(@PathVariable String musicId){
        musicService.addLikeMusic(musicId);
        return AjaxResult.success();
    }

    // 获取我喜欢的音乐
    @RequestMapping("/like/music")
    public TableDataInfo likeMusic(){
        startPage();
        Long userId = SecurityUtils.getUserId();
        List<MusicInfo> list = musicService.findLikeMusicByUser(userId);
        //musicService.createPlaylist();
        return getDataTableData(list);
    }
    // 删除我喜欢的音乐 cancel/like
    @RequestMapping("/cancel/like/{musicId}")
    public AjaxResult cancelLikeMusic(@PathVariable String musicId){
        musicService.cancelLikeMusic(musicId);
        return AjaxResult.success();
    }

//    // 新增历史
//    @RequestMapping("/history/add/{musicId}")
//    public AjaxResult addHistory(@PathVariable String musicId){
//        musicService.addHistoryMusic(musicId);
//        return AjaxResult.success();
//    }

    // 查询历史
    @RequestMapping("/history/music")
    public TableDataInfo historyMusic(){
        startPage();
        Long userId = SecurityUtils.getUserId();
        List<MusicInfo> list = musicService.findHistoryMusicByUser(userId);
        //musicService.createPlaylist();
        return getDataTableData(list);
    }

    // 获取音乐基本信息
    @RequestMapping("/getMusicInfo/{musicId}")
    public AjaxResult getMusicInfo(@PathVariable String musicId){
        Long userId = SecurityUtils.getUserId();
        return AjaxResult.success(musicService.getMusicInfo(userId,musicId));
    }


}
