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

import cn.dev33.satoken.annotation.SaCheckPermission;
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.ActivityFormReq;
import com.seer.teach.mp.admin.controller.resp.AdminActivityFormResp;
import com.seer.teach.mp.admin.service.IAdminActivityFormService;
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.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.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

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

    private final IAdminActivityFormService adminActivityFormService;

    @Operation(summary = "创建表单")
    @PostMapping
    @SaCheckPermission("mp:admin:activity:form:save")
    public ResultBean<Boolean> save(@Valid @RequestBody ActivityFormReq request) {
        Boolean result = adminActivityFormService.save(request);
        return ResultBean.success(result);
    }

    @Operation(summary = "更新表单")
    @PutMapping
    @SaCheckPermission("mp:admin:activity:form:update")
    public ResultBean<Boolean> update(@Valid @RequestBody ActivityFormReq request) {
        Boolean result = adminActivityFormService.update(request);
        return ResultBean.success(result);
    }

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

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

    @Operation(summary = "发布新版本")
    @PostMapping("/publish-new-version")
    @SaCheckPermission("mp:admin:activity:form:publish")
    public ResultBean<Boolean> publishNewVersion(@RequestBody @Valid ActivityFormReq req) {
        Boolean result = adminActivityFormService.publishNewVersion(req);
        return ResultBean.success(result);
    }
}