package com.goldenwater.slgc.controller;

import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.goldenwater.common.annotation.Log;
import com.goldenwater.common.core.controller.BaseController;
import com.goldenwater.common.core.domain.AjaxResult;
import com.goldenwater.common.core.page.TableDataInfo;
import com.goldenwater.common.enums.BusinessType;
import com.goldenwater.slgc.domain.Player;
import com.goldenwater.slgc.domain.PlayerItem;
import com.goldenwater.slgc.service.PlayerItemService;
import com.goldenwater.slgc.service.PlayerService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;

@Tag(name = "17. 播放器管理")
@RestController
@RequestMapping("/slgc/player")
public class PlayerController extends BaseController {
    @Autowired
    private PlayerService playerService;

    @Autowired
    private PlayerItemService playerItemService;

    // ========== 播放器配置 ==========

    @Operation(summary = "17.01 查询播放器配置列表")
    @GetMapping("/list")
    public TableDataInfo list(Player player) {
        startPage();
        List<Player> list = playerService.selectPlayerList(player);
        return getDataTable(list);
    }

    @Operation(summary = "17.02 获取播放器配置详细信息")
    @GetMapping(value = "/{plyId}")
    public AjaxResult getInfo(@PathVariable String plyId) {
        return success(playerService.selectPlayerById(plyId));
    }

    @Operation(summary = "17.03 新增播放器配置")
    @Log(title = "播放器管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Player player) {
        return toAjax(playerService.insertPlayer(player));
    }

    @Operation(summary = "17.04 修改播放器配置")
    @Log(title = "播放器管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Player player) {
        return toAjax(playerService.updatePlayer(player));
    }

    @Operation(summary = "17.05 删除播放器配置")
    @Log(title = "播放器管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{plyIds}")
    public AjaxResult remove(@PathVariable String[] plyIds) {
        return toAjax(playerService.deletePlayerByIds(plyIds));
    }

    @Operation(summary = "17.06 查询所有播放器配置")
    @GetMapping("/selectAll")
    public AjaxResult selectAll() {
        return success(playerService.selectAll());
    }

    // ========== 播放器项目 ==========

    @Operation(summary = "17.07 查询播放器项目列表")
    @GetMapping("/item/list")
    public TableDataInfo itemList(PlayerItem playerItem) {
        startPage();
        List<PlayerItem> list = playerItemService.selectPlayerItemList(playerItem);
        return getDataTable(list);
    }

    @Operation(summary = "17.08 获取播放器项目详细信息")
    @GetMapping("/item/{id}")
    public AjaxResult itemGetInfo(@PathVariable String id) {
        return success(playerItemService.selectPlayerItemById(id));
    }

    @Operation(summary = "17.09 新增播放器项目")
    @Log(title = "播放器项目管理", businessType = BusinessType.INSERT)
    @PostMapping("/item")
    public AjaxResult itemAdd(@RequestBody PlayerItem playerItem) {
        return toAjax(playerItemService.insertPlayerItem(playerItem));
    }

    @Operation(summary = "17.10 修改播放器项目")
    @Log(title = "播放器项目管理", businessType = BusinessType.UPDATE)
    @PutMapping("/item")
    public AjaxResult itemEdit(@RequestBody PlayerItem playerItem) {
        return toAjax(playerItemService.updatePlayerItem(playerItem));
    }

    @Operation(summary = "17.11 删除播放器项目")
    @Log(title = "播放器项目管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/item/{ids}")
    public AjaxResult itemRemove(@PathVariable String[] ids) {
        return toAjax(playerItemService.deletePlayerItemByIds(ids));
    }

    @Operation(summary = "17.12 根据播放器ID删除项目")
    @Log(title = "播放器项目管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/item/ply/{plyId}")
    public AjaxResult itemRemoveByPlyId(@PathVariable String plyId) {
        return toAjax(playerItemService.deleteByPlyId(plyId));
    }

    @Operation(summary = "17.13 查询所有播放器项目")
    @GetMapping("/item/selectAll")
    public AjaxResult itemSelectAll() {
        return success(playerItemService.selectAll());
    }
}
