package com.seer.teach.mp.admin.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.seer.teach.common.PageListBean;
import com.seer.teach.common.ResultBean;
import com.seer.teach.common.annotation.LogPrint;
import com.seer.teach.mp.admin.controller.req.AgentQueryReq;
import com.seer.teach.mp.admin.controller.req.MpAgentReq;
import com.seer.teach.mp.admin.controller.resp.AgentResp;
import com.seer.teach.mp.admin.service.AdminAgentService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
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 java.util.List;

@LogPrint
@RequiredArgsConstructor
@RestController
@Tag(name = "管理端 - 代理商")
@RequestMapping("/mp/agent")
public class AdminAgentController {

    private final AdminAgentService adminAgentService;

    @Operation(summary = "代理商列表")
    @PostMapping("/page-list")
    @SaCheckPermission("mp:admin:agent:list")
    public ResultBean<PageListBean<AgentResp>> pageList(@RequestBody @Validated AgentQueryReq query) {
        return ResultBean.success(adminAgentService.pageList(query));
    }

    @Operation(summary = "详情")
    @GetMapping("/{id}")
    @SaCheckPermission("mp:admin:agent:get")
    public ResultBean<AgentResp> getAgent(@PathVariable Integer id) {
        return ResultBean.success(adminAgentService.getAgentById(id));
    }

    @Operation(summary = "新增")
    @PostMapping
    @SaCheckPermission("mp:admin:agent:save")
    public ResultBean<Boolean> save(@RequestBody MpAgentReq req) {
        return ResultBean.success(adminAgentService.saveAgent(req));
    }

    @Operation(summary = "更新")
    @PutMapping
    @SaCheckPermission("mp:admin:agent:update")
    public ResultBean<Boolean> update(@RequestBody MpAgentReq req) {
        return ResultBean.success(adminAgentService.updateAgent(req));
    }

    @Operation(summary = "删除")
    @DeleteMapping
    @SaCheckPermission("mp:admin:agent:delete")
    public ResultBean<Boolean> delete(@RequestBody List<Integer> ids) {
        return ResultBean.success(adminAgentService.deleteById(ids));
    }
}