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.MpActivityQueryReq;
import com.seer.teach.mp.admin.controller.req.MpActivityReq;
import com.seer.teach.mp.admin.controller.resp.AdminActivityResp;
import com.seer.teach.mp.admin.service.IAdminActivityService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
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.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@LogPrint
@RequiredArgsConstructor
@RestController
@Tag(name = "管理端 - 活动")
@RequestMapping("/mp/agent/activity")
public class AdminActivityController {

    private final IAdminActivityService agentActivityService;

    @Operation(summary = "活动列表")
    @PostMapping("/page-list")
    @SaCheckPermission("mp:admin:agent:activity:list")
    public ResultBean<PageListBean<AdminActivityResp>> pageList(@RequestBody @Validated MpActivityQueryReq query) {
        return ResultBean.success(agentActivityService.pageList(query));
    }

    @Operation(summary = "创建或更新活动")
    @PostMapping("/save")
    @SaCheckPermission("mp:admin:agent:activity:save")
    public ResultBean<Boolean> save(@Valid @RequestBody MpActivityReq request) {
        return ResultBean.success(agentActivityService.saveOrUpdateActivity(request));
    }

    @Operation(summary = "删除活动")
    @DeleteMapping("/{id}")
    @SaCheckPermission("mp:admin:agent:activity:delete")
    public ResultBean<Boolean> delete(@PathVariable Integer id) {
        return ResultBean.success(agentActivityService.deleteActivity(id));
    }

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