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.AgentActivityParticipantQueryReq;
import com.seer.teach.mp.admin.controller.resp.AdminAgentActivityParticipantResp;
import com.seer.teach.mp.admin.service.IAdminAgentActivityParticipantService;
import com.seer.teach.mp.entity.MpAgentActivityParticipantEntity;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
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/activity/participant")
public class AdminAgentActivityParticipantController {

    private final IAdminAgentActivityParticipantService adminAgentActivityParticipantService;

    @Operation(summary = "代理商活动参与记录列表")
    @GetMapping("/page-list")
    @SaCheckPermission("mp:admin:agent:activity:participant:list")
    public ResultBean<PageListBean<AdminAgentActivityParticipantResp>> pageList(AgentActivityParticipantQueryReq query) {
        return ResultBean.success(adminAgentActivityParticipantService.pageList(query));
    }

    @Operation(summary = "详情")
    @GetMapping("/{id}")
    @SaCheckPermission("mp:admin:agent:activity:participant:get")
    public ResultBean<AdminAgentActivityParticipantResp> getParticipant(@PathVariable Integer id) {
        return ResultBean.success(adminAgentActivityParticipantService.getById(id));
    }

    @Operation(summary = "新增")
    @PostMapping
    @SaCheckPermission("mp:admin:agent:activity:participant:save")
    public ResultBean<Boolean> save(@RequestBody MpAgentActivityParticipantEntity participantEntity) {
        return ResultBean.success(adminAgentActivityParticipantService.saveParticipant(participantEntity));
    }

    @Operation(summary = "更新")
    @PutMapping
    @SaCheckPermission("mp:admin:agent:activity:participant:update")
    public ResultBean<Boolean> update(@RequestBody MpAgentActivityParticipantEntity participantEntity) {
        return ResultBean.success(adminAgentActivityParticipantService.updateParticipant(participantEntity));
    }

    @Operation(summary = "删除")
    @DeleteMapping
    @SaCheckPermission("mp:admin:agent:activity:participant:delete")
    public ResultBean<Boolean> delete(@RequestBody List<Integer> ids) {
        boolean result = true;
        for (Integer id : ids) {
            result &= adminAgentActivityParticipantService.deleteParticipant(id);
        }
        return ResultBean.success(result);
    }
}