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.resp.AdminActivityFormRelationResp;
import com.seer.teach.mp.admin.service.IAdminActivityFormRelationService;
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 java.util.List;

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

    private final IAdminActivityFormRelationService adminActivityFormRelationService;

    @Operation(summary = "为活动关联表单")
    @PostMapping("/associate")
    @SaCheckPermission("mp:admin:activity:form:relation:associate")
    public ResultBean<Boolean> associateFormWithActivity(
            @RequestParam Integer activityId,
            @RequestParam Integer templateId) {
        Boolean result = adminActivityFormRelationService.associateFormWithActivity(activityId, templateId);
        return ResultBean.success(result);
    }

    @Operation(summary = "解除活动与表单的关联")
    @DeleteMapping("/disassociate")
    @SaCheckPermission("mp:admin:activity:form:relation:disassociate")
    public ResultBean<Boolean> disassociateFormWithActivity(
            @RequestParam Integer activityId,
            @RequestParam Integer templateId) {
        Boolean result = adminActivityFormRelationService.disassociateFormWithActivity(activityId, templateId);
        return ResultBean.success(result);
    }

    @Operation(summary = "获取活动关联的表单列表")
    @GetMapping("/{activityId}")
    @SaCheckPermission("mp:admin:activity:form:relation:list")
    public ResultBean<List<AdminActivityFormRelationResp>> getFormsByActivity(@PathVariable Integer activityId) {
        List<AdminActivityFormRelationResp> result = adminActivityFormRelationService.getFormsByActivity(activityId);
        return ResultBean.success(result);
    }
}