package com.ycwl.basic.controller.pc;

import com.github.pagehelper.PageInfo;
import com.ycwl.basic.model.pc.device.entity.DeviceConfigEntity;
import com.ycwl.basic.model.pc.template.entity.TemplateConfigEntity;
import com.ycwl.basic.model.pc.template.entity.TemplateEntity;
import com.ycwl.basic.model.pc.template.req.TemplateReqQuery;
import com.ycwl.basic.model.pc.template.req.TemplateSortRequest;
import com.ycwl.basic.model.pc.template.resp.TemplateRespVO;
import com.ycwl.basic.service.pc.TemplateService;
import com.ycwl.basic.utils.ApiResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author：longbinbin
 * @Date：2024/12/3 16:11
 */
@RestController
@RequestMapping("/api/template/v1")
@Api(tags = "模板管理")
public class TemplateController {

    @Autowired
    private TemplateService templateService;

    @ApiOperation("分页查询模板")
    @PostMapping("/page")
    public ApiResponse<PageInfo<TemplateRespVO>> pageQuery(@RequestBody TemplateReqQuery templateReqQuery) {
        return templateService.pageQuery(templateReqQuery);
    }
    @ApiOperation("查询模板列表")
    @PostMapping("/list")
    public ApiResponse<List<TemplateRespVO>> list(@RequestBody TemplateReqQuery templateReqQuery) {
        return templateService.list(templateReqQuery);
    }
    @ApiOperation("查询模板详情")
    @GetMapping("getDetail/{id}")
    public ApiResponse<TemplateRespVO> getById(@PathVariable Long id) {
        return templateService.getById(id);
    }
    @ApiOperation("添加模板")
    @PostMapping("/add")
    public ApiResponse<Boolean> add(@RequestBody TemplateEntity template) {
        return templateService.add(template);
    }
    @ApiOperation("删除模板")
    @DeleteMapping("/delete/{id}")
    public ApiResponse<Integer> deleteById(@PathVariable Long id) {
        return templateService.deleteById(id);
    }
    @ApiOperation("修改模板")
    @PostMapping("/update")
    public ApiResponse<Boolean> update(@RequestBody TemplateEntity template) {
        return templateService.update(template);
    }
    @ApiOperation("修改模板状态")
    @PostMapping("/updateStatus/{id}")
    public ApiResponse<Boolean> updateStatus(@PathVariable("id") Long id) {
        return templateService.updateStatus(id);
    }

    @ApiOperation("排序模板")
    @PostMapping("/sort")
    public ApiResponse<Boolean> sortTemplate(@RequestBody TemplateSortRequest request) {
        return templateService.sortTemplate(request.getTemplateId(), request.getAfterTemplateId());
    }

    @GetMapping("/config/{id}")
    public ApiResponse<TemplateConfigEntity> getConfig(@PathVariable("id") Long id) {
        return ApiResponse.success(templateService.getConfig(id));
    }

    @PostMapping("/saveConfig/{configId}")
    public ApiResponse saveConfig(@PathVariable("configId") Long configId, @RequestBody TemplateConfigEntity deviceConfigEntity) {
        templateService.saveConfig(configId, deviceConfigEntity);
        return ApiResponse.success(null);
    }
}
