package com.test.musichouduan.controller;

import cn.dev33.satoken.annotation.SaCheckRole;
import cn.dev33.satoken.annotation.SaIgnore;
import com.test.musichouduan.dto.*;
import com.test.musichouduan.service.TypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 类型控制器
 */
@RestController
@RequestMapping("/api/type")
public class TypeController {

    @Autowired
    private TypeService typeService;

    /**
     * 获取音乐类型列表
     *
     * @return 响应结果
     */
    @SaIgnore
    @GetMapping("/music")
    public Result<List<MusicTypeDTO>> getMusicTypeList() {
        List<MusicTypeDTO> typeList = typeService.getMusicTypeList();
        return Result.success(typeList);
    }

    /**
     * 分页获取音乐类型列表
     *
     * @param page 页码
     * @param size 每页大小
     * @param keyword 关键字
     * @return 响应结果
     */
    @SaCheckRole("admin")
    @GetMapping("/music/page")
    public Result<PageResult<MusicTypeDTO>> getMusicTypePage(
            @RequestParam(defaultValue = "1") Integer page,
            @RequestParam(defaultValue = "10") Integer size,
            @RequestParam(required = false) String keyword) {
        PageResult<MusicTypeDTO> pageResult = typeService.getMusicTypePage(page, size, keyword);
        return Result.success(pageResult);
    }

    /**
     * 添加音乐类型
     *
     * @param musicTypeDTO 音乐类型DTO
     * @return 响应结果
     */
    @SaCheckRole("admin")
    @PostMapping("/music/add")
    public Result<MusicTypeDTO> addMusicType(@RequestBody MusicTypeDTO musicTypeDTO) {
        MusicTypeDTO result = typeService.addMusicType(musicTypeDTO);
        return Result.success("添加成功", result);
    }

    /**
     * 更新音乐类型
     *
     * @param id 音乐类型ID
     * @param musicTypeDTO 音乐类型DTO
     * @return 响应结果
     */
    @SaCheckRole("admin")
    @PutMapping("/music/{id}")
    public Result<MusicTypeDTO> updateMusicType(@PathVariable Long id, @RequestBody MusicTypeDTO musicTypeDTO) {
        MusicTypeDTO result = typeService.updateMusicType(id, musicTypeDTO);
        return Result.success("更新成功", result);
    }

    /**
     * 删除音乐类型
     *
     * @param id 音乐类型ID
     * @return 响应结果
     */
    @SaCheckRole("admin")
    @DeleteMapping("/music/{id}")
    public Result<Boolean> deleteMusicType(@PathVariable Long id) {
        boolean result = typeService.deleteMusicType(id);
        return Result.success("删除成功", result);
    }

    /**
     * 获取歌手类型列表
     *
     * @return 响应结果
     */
    @GetMapping("/singer")
    public Result<List<SingerTypeDTO>> getSingerTypeList() {
        List<SingerTypeDTO> typeList = typeService.getSingerTypeList();
        return Result.success(typeList);
    }

    /**
     * 分页获取歌手类型列表
     *
     * @param page 页码
     * @param size 每页大小
     * @param keyword 关键字
     * @return 响应结果
     */
    @SaCheckRole("admin")
    @GetMapping("/singer/page")
    public Result<PageResult<SingerTypeDTO>> getSingerTypePage(
            @RequestParam(defaultValue = "1") Integer page,
            @RequestParam(defaultValue = "10") Integer size,
            @RequestParam(required = false) String keyword) {
        PageResult<SingerTypeDTO> pageResult = typeService.getSingerTypePage(page, size, keyword);
        return Result.success(pageResult);
    }

    /**
     * 添加歌手类型
     *
     * @param singerTypeDTO 歌手类型DTO
     * @return 响应结果
     */
    @SaCheckRole("admin")
    @PostMapping("/singer/add")
    public Result<SingerTypeDTO> addSingerType(@RequestBody SingerTypeDTO singerTypeDTO) {
        SingerTypeDTO result = typeService.addSingerType(singerTypeDTO);
        return Result.success("添加成功", result);
    }

    /**
     * 更新歌手类型
     *
     * @param id 歌手类型ID
     * @param singerTypeDTO 歌手类型DTO
     * @return 响应结果
     */
    @SaCheckRole("admin")
    @PutMapping("/singer/{id}")
    public Result<SingerTypeDTO> updateSingerType(@PathVariable Long id, @RequestBody SingerTypeDTO singerTypeDTO) {
        SingerTypeDTO result = typeService.updateSingerType(id, singerTypeDTO);
        return Result.success("更新成功", result);
    }

    /**
     * 删除歌手类型
     *
     * @param id 歌手类型ID
     * @return 响应结果
     */
    @SaCheckRole("admin")
    @DeleteMapping("/singer/{id}")
    public Result<Boolean> deleteSingerType(@PathVariable Long id) {
        boolean result = typeService.deleteSingerType(id);
        return Result.success("删除成功", result);
    }

    /**
     * 获取歌单类型列表
     *
     * @return 响应结果
     */
    @GetMapping("/playlist")
    public Result<List<PlaylistTypeDTO>> getPlaylistTypeList() {
        List<PlaylistTypeDTO> typeList = typeService.getPlaylistTypeList();
        return Result.success(typeList);
    }

    /**
     * 分页获取歌单类型列表
     *
     * @param page 页码
     * @param size 每页大小
     * @param keyword 关键字
     * @return 响应结果
     */
    @SaCheckRole("admin")
    @GetMapping("/playlist/page")
    public Result<PageResult<PlaylistTypeDTO>> getPlaylistTypePage(
            @RequestParam(defaultValue = "1") Integer page,
            @RequestParam(defaultValue = "10") Integer size,
            @RequestParam(required = false) String keyword) {
        PageResult<PlaylistTypeDTO> pageResult = typeService.getPlaylistTypePage(page, size, keyword);
        return Result.success(pageResult);
    }

    /**
     * 添加歌单类型
     *
     * @param playlistTypeDTO 歌单类型DTO
     * @return 响应结果
     */
    @SaCheckRole("admin")
    @PostMapping("/playlist/add")
    public Result<PlaylistTypeDTO> addPlaylistType(@RequestBody PlaylistTypeDTO playlistTypeDTO) {
        PlaylistTypeDTO result = typeService.addPlaylistType(playlistTypeDTO);
        return Result.success("添加成功", result);
    }

    /**
     * 更新歌单类型
     *
     * @param id 歌单类型ID
     * @param playlistTypeDTO 歌单类型DTO
     * @return 响应结果
     */
    @SaCheckRole("admin")
    @PutMapping("/playlist/{id}")
    public Result<PlaylistTypeDTO> updatePlaylistType(@PathVariable Long id, @RequestBody PlaylistTypeDTO playlistTypeDTO) {
        PlaylistTypeDTO result = typeService.updatePlaylistType(id, playlistTypeDTO);
        return Result.success("更新成功", result);
    }

    /**
     * 删除歌单类型
     *
     * @param id 歌单类型ID
     * @return 响应结果
     */
    @SaCheckRole("admin")
    @DeleteMapping("/playlist/{id}")
    public Result<Boolean> deletePlaylistType(@PathVariable Long id) {
        boolean result = typeService.deletePlaylistType(id);
        return Result.success("删除成功", result);
    }
}
