package com.ho.business.controller;

import com.ho.business.service.ForwardColTemplateService;
import com.ho.business.vo.req.ForwardColTemplateReq;
import com.ho.business.vo.resp.ForwardColTemplateResp;
import com.ho.common.tools.constant.ContextConstant;
import com.ho.common.tools.exception.DataResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
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;

import java.util.List;

@RestController
@RequestMapping(ContextConstant.BUSINESS + "forwardColTemplate")
@Api(tags = "转发模板")
@Slf4j
public class ForwardColTemplateController {

    @Autowired
    ForwardColTemplateService forwardColTemplateService;

    /**
     * 编辑页面 新增接口
     *
     * @param template
     * @return
     */
    @PostMapping("addForwardColTemplate")
    @ApiOperation(value = "新增模板")
    public DataResult addForwardColTemplate(@RequestBody ForwardColTemplateReq template) {
        int i = forwardColTemplateService.addForwardColTemplate(template);
        return DataResult.success();
    }

    /**
     * 编辑页面 查看详情接口
     *
     * @param template
     * @return
     */
    @PostMapping("getForwardColTemplateDetail")
    @ApiOperation(value = "查看详情")
    public DataResult<List<ForwardColTemplateResp>> getForwardColTemplateDetail(@RequestBody ForwardColTemplateReq template) {
        if( template == null || template.getId() == null ){
            return DataResult.success();
        }
        List<ForwardColTemplateResp> forwardColTemplateDetail = forwardColTemplateService.getForwardColTemplateDetail(template);
        return DataResult.success(forwardColTemplateDetail);
    }


    /**
     * 编辑页面 编辑接口
     *
     * @param template
     * @return
     */
    @PostMapping("modifyForwardColTemplate")
    @ApiOperation(value = "编辑模板")
    public DataResult modifyForwardColTemplate(@RequestBody ForwardColTemplateReq template) {
        forwardColTemplateService.modifyForwardColTemplate(template);
        return DataResult.success();
    }

}
