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.DecryptionAnnotation;
import com.seer.teach.common.annotation.EncryptionAnnotation;
import com.seer.teach.common.annotation.LogPrint;
import com.seer.teach.mp.admin.controller.req.ActivityFormExecutionQueryReq;
import com.seer.teach.mp.admin.controller.resp.AdminActivityFormExecutionResp;
import com.seer.teach.mp.admin.service.IAdminActivityFormExecutionService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import jakarta.validation.Valid;

/**
 * <p>
 * 活动表单执行实例管理端控制器
 * </p>
 *
 * @author Lingma
 * @since 2026-01-10
 */
@Tag(name = "ADMIN - 活动表单执行实例")
@RestController
@RequestMapping("/activity/form/execution")
@LogPrint
@EncryptionAnnotation
@DecryptionAnnotation
@RequiredArgsConstructor
public class AdminActivityFormExecutionController {

    private final IAdminActivityFormExecutionService adminActivityFormExecutionService;

    @Operation(summary = "表单执行实例列表")
    @PostMapping("/page-list")
    @SaCheckPermission("mp:admin:activity:form:execution:list")
    public ResultBean<PageListBean<AdminActivityFormExecutionResp>> pageList(@RequestBody @Valid ActivityFormExecutionQueryReq query) {
        PageListBean<AdminActivityFormExecutionResp> result = adminActivityFormExecutionService.pageList(query);
        return ResultBean.success(result);
    }

    @Operation(summary = "创建或更新表单执行实例")
    @PostMapping("/save")
    @SaCheckPermission("mp:admin:activity:form:execution:save")
    public ResultBean<Boolean> save(@Valid @RequestBody ActivityFormExecutionQueryReq request) {
        Boolean result = adminActivityFormExecutionService.saveOrUpdate(request);
        return ResultBean.success(result);
    }

    @Operation(summary = "删除表单执行实例")
    @DeleteMapping("/{id}")
    @SaCheckPermission("mp:admin:activity:form:execution:delete")
    public ResultBean<Boolean> delete(@PathVariable Integer id) {
        Boolean result = adminActivityFormExecutionService.deleteById(id);
        return ResultBean.success(result);
    }

    @Operation(summary = "详情")
    @GetMapping("/{id}")
    @SaCheckPermission("mp:admin:activity:form:execution:get")
    public ResultBean<AdminActivityFormExecutionResp> get(@PathVariable Integer id) {
        AdminActivityFormExecutionResp result = adminActivityFormExecutionService.getById(id);
        return ResultBean.success(result);
    }
    
    @Operation(summary = "提交表单")
    @PostMapping("/submit/{id}")
    @SaCheckPermission("mp:admin:activity:form:execution:submit")
    public ResultBean<Boolean> submit(@PathVariable Integer id) {
        Boolean result = adminActivityFormExecutionService.submitById(id);
        return ResultBean.success(result);
    }
}