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.req.AgentActivityParticipantReq;
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 com.seer.teach.mp.service.IMpActivityService;
import com.seer.teach.mp.service.IMpAgentService;
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.*;

import java.util.List;

@LogPrint
@RequiredArgsConstructor
@RestController
@Tag(name = "管理端 - 代理商活动参与记录")
@RequestMapping("/mp/agent/activity/participant")
public class AdminAgentActivityParticipantController {

    private final IAdminAgentActivityParticipantService adminAgentActivityParticipantService;

    private final IMpAgentService mpAgentService;

    private final IMpActivityService mpActivityService;

    @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 @Validated AgentActivityParticipantReq req) {
        return ResultBean.success(adminAgentActivityParticipantService.saveParticipant(req));
    }

    @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) {
        return ResultBean.success(adminAgentActivityParticipantService.deleteById(ids));
    }


    @Operation(summary = "查询代理商名称")
    @GetMapping("/agent-name")
    public ResultBean<List<String>> getAgentName() {
        return ResultBean.success(mpAgentService.getAgentName());
    }

    @Operation(summary = "查询活动名称")
    @GetMapping("/activity-name")
    public ResultBean<List<String>> getActivityName() {
        return ResultBean.success(mpActivityService.getActivityName());
    }
}