package com.hys.app.controller.erp.use;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hys.app.converter.erp.SmsMailConverter;
import com.hys.app.framework.context.user.AdminUserContext;
import com.hys.app.model.erp.dos.MailSmsCountDO;
import com.hys.app.model.erp.entity.*;
import com.hys.app.model.erp.vo.MailSmsCountVO;
import com.hys.app.model.support.LogClient;
import com.hys.app.model.support.validator.annotation.Log;
import com.hys.app.model.system.dos.SmsMailTemplate;
import com.hys.app.model.system.dto.SmsMailTemplateDTO;
import com.hys.app.model.system.vo.SmsMailTemplateQuery;
import com.hys.app.model.system.vo.SmsMailTemplateVO;
import com.hys.app.service.erp.CompanyManager;
import com.hys.app.service.erp.MailSmsCountManager;
import com.hys.app.service.erp.SmsMailManager;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.math.BigDecimal;
import java.util.List;

@Api(tags = "公司")
@RestController
@RequestMapping("/admin/erp/SmsMailTemplate")
@AllArgsConstructor
public class SmsMailController {

    private SmsMailManager smsMailManager;
    private MailSmsCountManager mailSmsCountManager;

    @PostMapping("createTemplate")
    @ApiOperation(value = "创建模板")
    @Log(client = LogClient.admin, detail = "创建名称为[${smsMailTemplateDTO.name}]的模板")
    public Long createTemplate(@Valid @RequestBody SmsMailTemplateDTO smsMailTemplateDTO) {
        return smsMailManager.createTemplate(smsMailTemplateDTO);
    }

    @PostMapping("updateTemplate/{id}")
    @ApiOperation(value = "修改模板")
    @Log(client = LogClient.admin, detail = "修改名称为[${companyDO.name}]的公司信息")
    public Long updateTemplate(@Valid @RequestBody SmsMailTemplateDTO smsMailTemplateDTO, @PathVariable Long id) {
        return smsMailManager.updateTemplate(smsMailTemplateDTO, id);
    }

    @GetMapping("getById/{id}")
    @ApiOperation(value = "获取模板信息")
    public SmsMailTemplateVO renewCompanyDifference(@PathVariable Long id) {
        return SmsMailConverter.INSTANCE.convert(smsMailManager.getById(id));
    }

    @GetMapping()
    @ApiOperation(value = "模板分页")
    public IPage<SmsMailTemplateVO> queryTemplate(SmsMailTemplateQuery query) {
        return smsMailManager.queryTemplate(query);
    }

    @PostMapping("delete/{id}")
    @ApiOperation(value = "删除模板")
    public void delete(@PathVariable Long id) {
        smsMailManager.delete(id);
    }

    @PostMapping("alterStatus/{id}")
    @ApiOperation(value = "修改模板状态")
    public void alterStatus(@PathVariable Long id) {
        SmsMailTemplate byId = smsMailManager.getById(id);
        byId.setEnableStatus(!byId.getEnableStatus());
        smsMailManager.updateById(byId);
    }
    @GetMapping("getSendNumByCompany")
    @ApiOperation(value = "获取各公司")
    public IPage<MailSmsCountVO> getSendNumByCompany(MailSmsCountQuery query) {
        return mailSmsCountManager.getPage(query);
    }
}
