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.AgentActivityLogQueryReq;
import com.seer.teach.mp.admin.controller.resp.AdminAgentActivityLogResp;
import com.seer.teach.mp.admin.service.IAdminAgentActivityLogService;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
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/log")
public class AdminAgentActivityLogController {

    private final IAdminAgentActivityLogService adminAgentActivityLogService;

    @Operation(summary = "代理商活动操作日志列表")
    @PostMapping("/page-list")
    @SaCheckPermission("mp:admin:agent:activity:log:list")
    public ResultBean<PageListBean<AdminAgentActivityLogResp>> pageList(@RequestBody @Validated AgentActivityLogQueryReq query) {
        return ResultBean.success(adminAgentActivityLogService.pageList(query));
    }

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

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