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

import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.dev33.satoken.stp.StpUtil;
import com.seer.teach.common.PageListBean;
import com.seer.teach.common.ResultBean;
import com.seer.teach.common.annotation.DecryptionAnnotation;
import com.seer.teach.common.annotation.EncryptionAnnotation;
import com.seer.teach.common.annotation.LogPrint;
import com.seer.teach.mp.app.controller.req.AppAgentActivityQueryReq;
import com.seer.teach.mp.app.controller.resp.AppActivityResp;
import com.seer.teach.mp.app.service.IAppActivityService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 代理商活动App控制器
 * </p>
 *
 * @author Lingma
 * @since 2025-12-29
 */
@Tag(name = "APP - 活动列表")
@RestController
@RequestMapping("/app/activity")
@LogPrint
@EncryptionAnnotation
@DecryptionAnnotation
@RequiredArgsConstructor
public class AppMpActivityController {

    private final IAppActivityService agentActivityService;

    @Operation(summary = "活动列表")
    @GetMapping("/page-list")
    @SaCheckPermission("mp:app:agent:activity:list")
    public ResultBean<PageListBean<AppActivityResp>> pageList(AppAgentActivityQueryReq query) {
        Integer userId = StpUtil.getLoginIdAsInt();
        return ResultBean.success(agentActivityService.pageList(query,userId));
    }

    @Operation(summary = "查看活动详情")
    @GetMapping("/{id}")
    @SaCheckPermission("mp:app:agent:activity:detail")
    public ResultBean<AppActivityResp> getDetail(@PathVariable Integer id) {
        return ResultBean.success(agentActivityService.getById(id));
    }

    @Operation(summary = "活动二维码")
    @GetMapping("/{agentId}/{activityId}/qrcode")
    @SaCheckPermission("mp:app:agent:activity:qrcode")
    public ResultBean<String> getQrCode(@PathVariable("agentId") Integer agentId, @PathVariable("activityId") Integer activityId, @RequestParam("appId") String appId) {
        Integer userId = StpUtil.getLoginIdAsInt();
        return ResultBean.success(agentActivityService.getQrCode(userId,agentId,activityId,appId));
    }
}