package com.usky.meeting.controller.web;


import com.usky.common.core.bean.ApiResult;
import com.usky.common.core.bean.CommonPage;
import com.usky.common.log.annotation.Log;
import com.usky.common.log.enums.BusinessType;
import com.usky.meeting.domain.MeetingTemplate;
import com.usky.meeting.service.MeetingTemplateService;
import com.usky.meeting.service.vo.MeetingTemplateRequestVO;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import org.springframework.stereotype.Controller;

import java.util.List;

/**
 * <p>
 * 会议屏模板表 前端控制器
 * </p>
 *
 * @author fu
 * @since 2025-11-18
 */
@Slf4j
@RestController
@RequestMapping("/meetingTemplate")
public class MeetingTemplateController {

    @Autowired
    private MeetingTemplateService meetingTemplateService;

    /**
     * 新增和修改
     * @param meetingTemplate  会议屏模板
     * @return 添加结果
     */
    @PostMapping("/addAndUpdate")
    @Log(title = "新增/修改会议屏模板", businessType = BusinessType.INSERT)
    public ApiResult<Void> addAndUpdate(@RequestBody MeetingTemplate meetingTemplate) {
        meetingTemplateService.addAndUpdate(meetingTemplate);
        return ApiResult.success();
    }

    /**
     * 删除
     * @param templateId  会议屏模板id
     * @return 删除结果
     */
    @DeleteMapping("/{templateId}")
    @Log(title = "删除会议屏模板", businessType = BusinessType.DELETE)
    public ApiResult<Void> remove(@PathVariable Long templateId) {
        meetingTemplateService.deleteById(templateId);
        return ApiResult.success();
    }

    /**
     * 获取会议屏模板列表
     * @param name  模板名称
     * @param type  模板类型
     * @param layout  模板布局
     * @return 模板列表
     */
    @GetMapping("/templateList")
    public ApiResult<CommonPage<MeetingTemplate>> list(@RequestParam(defaultValue = "1") Integer pageNum,
                                                       @RequestParam(defaultValue = "10") Integer pageSize,
                                                       @RequestParam(required = false) String name,
                                                       @RequestParam(required = false) Integer type,
                                                       @RequestParam(required = false) String layout) {
        return ApiResult.success(meetingTemplateService.templateList(pageNum, pageSize, name, type, layout));
    }

    @PutMapping("/batchPublishing")
    @Log(title = "批量发布会议屏模板", businessType = BusinessType.UPDATE)
    public ApiResult<Void> batchPublishing(@RequestBody MeetingTemplateRequestVO requestVO) {
        meetingTemplateService.batchPublishing(requestVO);
        return ApiResult.success();
    }
}

