package com.czg.controller.admin;

import com.czg.account.dto.song.BaseShopSongDTO;
import com.czg.account.dto.song.ShopSongAddDTO;
import com.czg.account.dto.song.ShopSongEditDTO;
import com.czg.account.entity.ShopSong;
import com.czg.account.service.ShopSongService;
import com.czg.annotation.SaAdminCheckPermission;
import com.czg.resp.CzgResult;
import com.czg.sa.StpKit;
import com.czg.utils.PageUtil;
import com.mybatisflex.core.paginate.Page;
import com.mybatisflex.core.query.QueryWrapper;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;


/**
 * 点歌相关接口
 * @author Administrator
 */
@RestController
@RequestMapping("/admin/shopSong")
public class ShopSongController {
    @Resource
    private ShopSongService shopSongService;

    /**
     * 点歌页面地址
     * @return url
     */
    @SaAdminCheckPermission(parentName = "点歌管理", value = "shopSong:url", name = "点歌页面地址")
    @GetMapping("/url")
    public CzgResult<String> getSongUrl(){
        return CzgResult.success(shopSongService.getSongUrl(StpKit.USER.getShopId()));
    }

    /**
     * 歌曲列表
     * @return 分页数据
     */
    @SaAdminCheckPermission(parentName = "点歌管理", value = "shopSong:list", name = "店铺歌曲查询")
    @GetMapping
    public CzgResult<Page<ShopSong>> list(){
      return CzgResult.success(shopSongService.page(PageUtil.buildPage(), new QueryWrapper().eq(ShopSong::getShopId, StpKit.USER.getShopId()).orderBy(ShopSong::getCreateTime, false)));
    }

    /**
     * 歌曲详情
     * @return 分页数据
     */
    @SaAdminCheckPermission(parentName = "点歌管理", value = "shopSong:detail", name = "店铺歌曲详情")
    @GetMapping("/detail")
    public CzgResult<ShopSong> detail(@RequestParam Integer id){
        return CzgResult.success(shopSongService.getOne(new QueryWrapper().eq(ShopSong::getShopId, StpKit.USER.getShopId()).eq(ShopSong::getId, id)));
    }


    /**
     * 店铺歌曲新增
     * @param shopSongAddDTO 歌曲数据
     * @return 是否成功
     */
    @SaAdminCheckPermission(parentName = "点歌管理", value = "shopSong:add", name = "店铺歌曲新增")
    @PostMapping
    public CzgResult<Boolean> add(@RequestBody @Validated ShopSongAddDTO shopSongAddDTO){
        return CzgResult.success(shopSongService.add(StpKit.USER.getShopId(), shopSongAddDTO));
    }

    /**
     * 歌曲修改
     * @param shopSongEditDTO 修改信息
     * @return 是否成功
     */
    @SaAdminCheckPermission(parentName = "点歌管理", value = "shopSong:edit", name = "店铺歌曲修改")
    @PutMapping
    public CzgResult<Boolean> edit(@RequestBody @Validated ShopSongEditDTO shopSongEditDTO){
        return CzgResult.success(shopSongService.edit(StpKit.USER.getShopId(), shopSongEditDTO));
    }

    /**
     * 歌曲删除
     * @param shopSongEditDTO 删除信息
     * @return 是否成功
     */
    @SaAdminCheckPermission(parentName = "点歌管理", value = "shopSong:del", name = "店铺歌曲删除")
    @DeleteMapping
    public CzgResult<Boolean> delete(@RequestBody @Validated BaseShopSongDTO shopSongEditDTO){
        return CzgResult.success(shopSongService.remove(new QueryWrapper().eq(ShopSong::getShopId, StpKit.USER.getShopId()).eq(ShopSong::getId, shopSongEditDTO.getId())));
    }


}
