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

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.seer.teach.common.ResultBean;
import com.seer.teach.mp.entity.MpTemplateMessageMappingEntity;
import com.seer.teach.mp.service.IMpTemplateMessageMappingService;
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 java.util.List;

@RequiredArgsConstructor
@RestController
@RequestMapping("/mp/template-message/mapping")
@Tag(name = "管理端 - 模板消息映射")
public class AdminTemplateMessageMappingController {

    private final IMpTemplateMessageMappingService mpTemplateMessageMappingService;

    @GetMapping("/list")
    @Operation(summary = "获取模板消息映射列表")
    @SaCheckPermission("mp:admin:template:message:mapping:list")
    public ResultBean<List<MpTemplateMessageMappingEntity>> list(@RequestParam("templateId") String templateId) {
        return ResultBean.success(mpTemplateMessageMappingService.list(new LambdaQueryWrapper<>(MpTemplateMessageMappingEntity.class).eq(MpTemplateMessageMappingEntity::getTemplateId, templateId)));
    }

    @PostMapping("/{templateId}/update")
    @Operation(summary = "更新模板消息映射")
    @SaCheckPermission("mp:admin:template:message:mapping:update")
    public ResultBean<Boolean> update(@PathVariable("templateId") String templateId,@RequestBody List<MpTemplateMessageMappingEntity> list) {
        return ResultBean.success(mpTemplateMessageMappingService.saveOrUpdateBatch(list));
    }
}