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.mp.admin.controller.req.MpAccountPageReq;
import com.seer.teach.mp.admin.controller.req.MpAccountReq;
import com.seer.teach.mp.admin.controller.resp.AdminMpAccountResp;
import com.seer.teach.mp.admin.service.AdminMpAccountService;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import jakarta.validation.Valid;
import java.util.List;

/**
 * <p>
 * 公众号账号表 前端控制器
 * </p>
 *
 * @author Wang
 * @since 2025-08-02 15:45:13
 */
@Tag(name = "管理端 - 公众号账号")
@RequiredArgsConstructor
@RestController
@RequestMapping("/mp/account")
public class AdminMpAccountController {
    
    private final AdminMpAccountService mpAccountService;

    @PostMapping("/create")
    @Operation(summary = "创建公众号账号")
    @SaCheckPermission("admin:mp:account:create")
    public ResultBean<Boolean> createAccount(@Valid @RequestBody MpAccountReq createReqVO) {
        return ResultBean.success(mpAccountService.createAccount(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新公众号账号")
    @SaCheckPermission("admin:mp:account:update")
    public ResultBean<Boolean> updateAccount(@Valid @RequestBody MpAccountReq updateReqVO) {
        return ResultBean.success(mpAccountService.updateAccount(updateReqVO));
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除公众号账号")
    @SaCheckPermission("admin:mp:account:delete")
    public ResultBean<Boolean> deleteAccount(@RequestParam("id") Integer id) {
        return ResultBean.success(mpAccountService.deleteAccount(id));
    }

    @GetMapping("/detail")
    @Operation(summary = "获得公众号账号")
    @SaCheckPermission("admin:mp:account:query")
    public ResultBean<AdminMpAccountResp> getAccount(@RequestParam("id") Integer id) {
        return ResultBean.success(mpAccountService.getAccount(id));
    }

    @PostMapping("/paged")
    @Operation(summary = "获得公众号账号分页")
    @SaCheckPermission("admin:mp:account:query")
    public ResultBean<PageListBean<AdminMpAccountResp>> getAccountPage(@Valid @RequestBody MpAccountPageReq pageVO) {
        return ResultBean.success(mpAccountService.getAccountPage(pageVO));
    }

    @GetMapping("/list")
    @Operation(summary = "获取公众号账号信息列表")
    @SaCheckPermission("admin:mp:account:query")
    public ResultBean<List<AdminMpAccountResp>> getAccountList() {
        return ResultBean.success(mpAccountService.getAccountList());
    }

    @PostMapping("/generate-qr-code")
    @Operation(summary = "生成公众号二维码")
    @SaCheckPermission("admin:mp:account:qr-code'")
    public ResultBean<Boolean> generateAccountQrCode(@RequestParam("id") Integer id,@RequestParam("场景值") String sceneStr) {
        return ResultBean.success(mpAccountService.generateAccountQrCode(id,sceneStr));
    }
}