package com.gree.mall.manager.controller.admin;

import com.gree.mall.manager.bean.admin.reqDto.AdminCompanyWechatTemplateUpdateReqDto;
import com.gree.mall.manager.helper.ResponseHelper;
import com.gree.mall.manager.logic.admin.AdminCompanyWechatTemplateLogic;
import com.gree.mall.manager.plus.entity.AdminCompanyWechatTemplate;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@RestController
@Api(value = "小程序模板", tags ={"小程序模板"} )
@RequestMapping(value = "/admin/company/template", produces = "application/json; charset=utf-8")
public class AdminCompanyWechatTemplateController {

    @Autowired
    private AdminCompanyWechatTemplateLogic adminCompanyWechatTemplateLogic;



    @GetMapping("/detail")
    @ApiOperation("获取企业下模板")
    public ResponseHelper<List<AdminCompanyWechatTemplate>> getTemplate() {


        return ResponseHelper.success(adminCompanyWechatTemplateLogic.getTemplate());
    }


    @PostMapping("/updateTemplate")
    @ApiOperation("更改模板信息")
    public ResponseHelper updateTemplate(HttpServletRequest request,@RequestBody AdminCompanyWechatTemplate adminCompanyWechatTemplate) {
        adminCompanyWechatTemplateLogic.updateTemplate(request, adminCompanyWechatTemplate);
        return ResponseHelper.success();
    }

    @PostMapping("/updateCompanyWithTemplate")
    @ApiOperation("更改企业信息和模板信息")
    public ResponseHelper updateCompanyWithTemplate(@RequestBody AdminCompanyWechatTemplateUpdateReqDto reqDto) {
        adminCompanyWechatTemplateLogic.updateCompanyWithTemplate(reqDto);
        return ResponseHelper.success();
    }


    @PostMapping("/initCompanyWechatTemplate")
    @ApiOperation("初始化企业微信模板")
    public ResponseHelper initCompanyWechatTemplate(
            @ApiParam(required = true,value = "企业微信id")@RequestParam String companyWechatId,
            @ApiParam(required = true,value = "企业名称")@RequestParam String companyName
    ) {

        adminCompanyWechatTemplateLogic.initCompanyWechatTemplate(companyWechatId, companyName);
        return ResponseHelper.success();
    }
}
