package com.ycwl.basic.controller.pc;

import com.github.pagehelper.PageInfo;
import com.ycwl.basic.model.pc.notify.entity.WechatSubscribeEventTemplateEntity;
import com.ycwl.basic.model.pc.notify.entity.WechatSubscribeSceneTemplateEntity;
import com.ycwl.basic.model.pc.notify.entity.WechatSubscribeSendLogEntity;
import com.ycwl.basic.model.pc.notify.entity.WechatSubscribeTemplateConfigEntity;
import com.ycwl.basic.model.pc.notify.req.WechatSubscribeEventTemplatePageReq;
import com.ycwl.basic.model.pc.notify.req.WechatSubscribeEventTemplateSaveReq;
import com.ycwl.basic.model.pc.notify.req.WechatSubscribeSceneTemplatePageReq;
import com.ycwl.basic.model.pc.notify.req.WechatSubscribeSceneTemplateSaveReq;
import com.ycwl.basic.model.pc.notify.req.WechatSubscribeSendLogPageReq;
import com.ycwl.basic.model.pc.notify.req.WechatSubscribeTemplateConfigPageReq;
import com.ycwl.basic.model.pc.notify.req.WechatSubscribeTemplateConfigSaveReq;
import com.ycwl.basic.service.pc.WechatSubscribeNotifyAdminService;
import com.ycwl.basic.utils.ApiResponse;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
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.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 微信小程序订阅消息：配置管理（管理后台）
 *
 * @Author: System
 * @Date: 2025/12/31
 */
@Slf4j
@RestController
@RequestMapping("/api/wechatSubscribeNotify/v1")
@RequiredArgsConstructor
public class WechatSubscribeNotifyAdminController {

    private final WechatSubscribeNotifyAdminService adminService;

    // ========================= 模板配置 =========================

    @PostMapping("/templateConfig/page")
    public ApiResponse<PageInfo<WechatSubscribeTemplateConfigEntity>> pageTemplateConfig(
            @RequestBody WechatSubscribeTemplateConfigPageReq req) {
        return adminService.pageTemplateConfig(req);
    }

    @GetMapping("/templateConfig/detail/{id}")
    public ApiResponse<WechatSubscribeTemplateConfigEntity> getTemplateConfig(@PathVariable("id") Long id) {
        return adminService.getTemplateConfig(id);
    }

    @PostMapping("/templateConfig/save")
    public ApiResponse<Boolean> saveTemplateConfig(@RequestBody WechatSubscribeTemplateConfigSaveReq req) {
        return adminService.saveTemplateConfig(req);
    }

    @DeleteMapping("/templateConfig/delete/{id}")
    public ApiResponse<Boolean> deleteTemplateConfig(@PathVariable("id") Long id) {
        return adminService.deleteTemplateConfig(id);
    }

    // ========================= 场景映射 =========================

    @PostMapping("/sceneTemplate/page")
    public ApiResponse<PageInfo<WechatSubscribeSceneTemplateEntity>> pageSceneTemplate(
            @RequestBody WechatSubscribeSceneTemplatePageReq req) {
        return adminService.pageSceneTemplate(req);
    }

    @GetMapping("/sceneTemplate/detail/{id}")
    public ApiResponse<WechatSubscribeSceneTemplateEntity> getSceneTemplate(@PathVariable("id") Long id) {
        return adminService.getSceneTemplate(id);
    }

    @PostMapping("/sceneTemplate/save")
    public ApiResponse<Boolean> saveSceneTemplate(@RequestBody WechatSubscribeSceneTemplateSaveReq req) {
        return adminService.saveSceneTemplate(req);
    }

    @DeleteMapping("/sceneTemplate/delete/{id}")
    public ApiResponse<Boolean> deleteSceneTemplate(@PathVariable("id") Long id) {
        return adminService.deleteSceneTemplate(id);
    }

    // ========================= 事件映射 =========================

    @PostMapping("/eventTemplate/page")
    public ApiResponse<PageInfo<WechatSubscribeEventTemplateEntity>> pageEventTemplate(
            @RequestBody WechatSubscribeEventTemplatePageReq req) {
        return adminService.pageEventTemplate(req);
    }

    @GetMapping("/eventTemplate/detail/{id}")
    public ApiResponse<WechatSubscribeEventTemplateEntity> getEventTemplate(@PathVariable("id") Long id) {
        return adminService.getEventTemplate(id);
    }

    @PostMapping("/eventTemplate/save")
    public ApiResponse<Boolean> saveEventTemplate(@RequestBody WechatSubscribeEventTemplateSaveReq req) {
        return adminService.saveEventTemplate(req);
    }

    @DeleteMapping("/eventTemplate/delete/{id}")
    public ApiResponse<Boolean> deleteEventTemplate(@PathVariable("id") Long id) {
        return adminService.deleteEventTemplate(id);
    }

    // ========================= 发送日志 =========================

    @PostMapping("/sendLog/page")
    public ApiResponse<PageInfo<WechatSubscribeSendLogEntity>> pageSendLog(@RequestBody WechatSubscribeSendLogPageReq req) {
        return adminService.pageSendLog(req);
    }

    @GetMapping("/sendLog/detail/{id}")
    public ApiResponse<WechatSubscribeSendLogEntity> getSendLog(@PathVariable("id") Long id) {
        return adminService.getSendLog(id);
    }
}

