package org.dromara.game.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import lombok.RequiredArgsConstructor;
import org.dromara.common.core.domain.R;
import org.dromara.common.core.validate.AddGroup;
import org.dromara.common.core.validate.EditGroup;
import org.dromara.common.excel.utils.ExcelUtil;
import org.dromara.common.idempotent.annotation.RepeatSubmit;
import org.dromara.common.log.annotation.Log;
import org.dromara.common.log.enums.BusinessType;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.mybatis.core.page.TableDataInfo;
import org.dromara.common.web.core.BaseController;
import org.dromara.game.domain.bo.PlatProductProxyBo;
import org.dromara.game.domain.vo.PlatProductProxyVo;
import org.dromara.game.service.IPlatProductProxyService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 产品代理商
 *
 * @author Hixon
 * @date 2024-08-07
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/game/productProxy")
public class PlatProductProxyController extends BaseController {

    private final IPlatProductProxyService platProductProxyService;

    /**
     * 查询产品代理商列表
     */
    @SaCheckPermission("game:productProxy:list")
    @GetMapping("/list")
    public TableDataInfo<PlatProductProxyVo> list(PlatProductProxyBo bo, PageQuery pageQuery) {
        return platProductProxyService.queryPageList(bo, pageQuery);
    }

    /**
     * 查询产品代理商列表
     */
    @SaCheckPermission("game:productProxy:list")
    @GetMapping("/all")
    public List<PlatProductProxyVo> all() {
        PlatProductProxyBo bo = new PlatProductProxyBo();
        return platProductProxyService.queryList(bo);
    }

    /**
     * 导出产品代理商列表
     */
    @SaCheckPermission("game:productProxy:export")
    @Log(title = "产品代理商", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(PlatProductProxyBo bo, HttpServletResponse response) {
        List<PlatProductProxyVo> list = platProductProxyService.queryList(bo);
        ExcelUtil.exportExcel(list, "产品代理商", PlatProductProxyVo.class, response);
    }

    /**
     * 获取产品代理商详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("game:productProxy:query")
    @GetMapping("/{id}")
    public R<PlatProductProxyVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long id) {
        return R.ok(platProductProxyService.queryById(id));
    }

    /**
     * 新增产品代理商
     */
    @SaCheckPermission("game:productProxy:add")
    @Log(title = "产品代理商", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody PlatProductProxyBo bo) {
        return toAjax(platProductProxyService.insertByBo(bo));
    }

    /**
     * 修改产品代理商
     */
    @SaCheckPermission("game:productProxy:edit")
    @Log(title = "产品代理商", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody PlatProductProxyBo bo) {
        return toAjax(platProductProxyService.updateByBo(bo));
    }

    /**
     * 删除产品代理商
     *
     * @param ids 主键串
     */
    @SaCheckPermission("game:productProxy:remove")
    @Log(title = "产品代理商", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        return toAjax(platProductProxyService.deleteWithValidByIds(List.of(ids), true));
    }
}
