package com.tofly.feesapi.sms.controller;

import cn.hutool.core.collection.CollectionUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tofly.common.core.util.StringUtil;
import com.tofly.feesapi.common.core.ResultRespone;

import com.tofly.feesapi.common.core.vo.PageResult;
import com.tofly.feesapi.sfgl.entity.vo.YyqfmxSumSelect;
import com.tofly.feesapi.sms.entity.dto.SmsMessageDto;
import com.tofly.feesapi.sms.entity.dto.SendTxlxMessageDto;
import com.tofly.feesapi.sms.entity.dto.SmsMessageYhxxDto;
import com.tofly.feesapi.sms.entity.vo.SmsMessageVo;
import com.tofly.feesapi.sms.entity.vo.SmsMessageYhxxVo;
import com.tofly.feesapi.sms.service.ISmsMessageService;
import com.tofly.feesapi.yhgl.service.YhsjqxService;
import lombok.AllArgsConstructor;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import org.springframework.web.bind.annotation.ModelAttribute;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * 短信消息
 */
@RestController
@RequestMapping("/smsmessage")
@Api(tags = "短信模块-短信消息接口")
public class SmsMessageController {

    @Autowired
    private ISmsMessageService ISmsMessageService;
    @Autowired
    private YhsjqxService yhsjqxService;

    @GetMapping("/page")
    @ApiOperation(value = "分页查询")
    public ResultRespone<Page<SmsMessageVo>> getSmsMessagePage(Page page, @ModelAttribute SmsMessageDto smsmessageDto) {
        ResultRespone<Page<SmsMessageVo>> resultRespone = new ResultRespone<>();
        try {
            Page<SmsMessageVo> smsmessagePage = ISmsMessageService.getSmsMessagePage(page, smsmessageDto);
            resultRespone.setCode(1);
            resultRespone.setResult(smsmessagePage);
        } catch (RuntimeException e) {
            resultRespone.setCode(-1);
            resultRespone.setMessage(e.getMessage());
        }
        return resultRespone;
    }

    @GetMapping("/pageyhxx")
    @ApiOperation(value = "分页查询-临时公告短信用户消息")
    public ResultRespone<Page<SmsMessageYhxxVo>> getSmsMessageYhxxPage(Page page, @ModelAttribute SmsMessageYhxxDto dto) {
        ResultRespone<Page<SmsMessageYhxxVo>> resultRespone = new ResultRespone<>();
        try {
            Page<SmsMessageYhxxVo> smsmessagePage = ISmsMessageService.getSmsMessageYhxxVoList(page, dto);
            resultRespone.setCode(1);
            resultRespone.setResult(smsmessagePage);
        } catch (RuntimeException e) {
            resultRespone.setCode(-1);
            resultRespone.setMessage(e.getMessage());
        }
        return resultRespone;
    }

    @GetMapping("/pageyhqfxx")
    @ApiOperation(value = "分页查询-用户欠费信息合计查询")
    public ResultRespone<Page<SmsMessageYhxxVo>> getSmsMessageYhqfxxPage(Page page, @ModelAttribute SmsMessageYhxxDto dto) {
        ResultRespone<Page<SmsMessageYhxxVo>> resultRespone = new ResultRespone<>();
        try {
            Page<SmsMessageYhxxVo> smsmessagePage = ISmsMessageService.getSmsMessageYhqfxxVoList(page, dto);
            resultRespone.setCode(1);
            resultRespone.setResult(smsmessagePage);
        } catch (RuntimeException e) {
            resultRespone.setCode(-1);
            resultRespone.setMessage(e.getMessage());
        }
        return resultRespone;
    }

    @GetMapping("/pageyff")
    @ApiOperation(value = "分页查询-预付费用户欠费小于10元用户查询")
    public ResultRespone<Page<SmsMessageYhxxVo>> getSmsMessageyffPage(Page page, @ModelAttribute SmsMessageYhxxDto smsmessageDto) {
        ResultRespone<Page<SmsMessageYhxxVo>> resultRespone = new ResultRespone<>();
        try {
            Page<SmsMessageYhxxVo> smsmessagePage = ISmsMessageService.getSmsMessageyffVoPage(page, smsmessageDto);
            resultRespone.setCode(1);
            resultRespone.setResult(smsmessagePage);
        } catch (RuntimeException e) {
            resultRespone.setCode(-1);
            resultRespone.setMessage(e.getMessage());
        }
        return resultRespone;
    }

    @GetMapping("/{id}")
    @ApiOperation(value = "通过ID查询")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "ID", required = true, dataType = "String")
    })
    public ResultRespone getById(@PathVariable("id") String id) {
        return ResultRespone.success(ISmsMessageService.getById(id));
    }

    @ApiOperation(value = "通过ID删除短信消息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "ID", required = true, dataType = "String")
    })
    @DeleteMapping("/{id}")
    public ResultRespone removeById(@PathVariable String id) {
        return ResultRespone.success(ISmsMessageService.removeById(id));
    }

    @ApiOperation(value = "通过ID批量删除短信消息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "ids", value = "批量删除，多个id以逗号隔开", required = true, dataType = "String")
    })
    @DeleteMapping("/deleteByIds")
    public ResultRespone removeByIds(String ids) {
        return ResultRespone.success(ISmsMessageService.removeByIds(Arrays.asList(ids.split(","))));
    }

    @ApiOperation(value = "通过id批量重新发送短信")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "ids", value = "批量删除，多个id以逗号隔开", required = true, dataType = "String")
    })
    @PostMapping("/reSendByIds")
    public ResultRespone reSendByIds(String ids) {
        return ResultRespone.success(ISmsMessageService.reSendByIds(ids));
    }

    @ApiOperation(value = "自定义发送短信")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "phone", value = "短信号码", required = true, dataType = "String"),
            @ApiImplicitParam(name = "content", value = "短信内容", required = true, dataType = "String"),
    })
    @PostMapping("/customizeSendMessage")
    public ResultRespone customizeSendMessage(String phone, String content) {
        return ResultRespone.success(ISmsMessageService.customizeSendMessage(phone, content));
    }

    @ApiOperation(value = "批量发送自定义短信消息")
    @PostMapping("/batchSendMessageYhxx")
    public ResultRespone batchSendMessageYhxx(@RequestBody SmsMessageYhxxDto dto) {
        return ResultRespone.success(ISmsMessageService.batchSendMessageYhxx(dto));
    }

    /**
     * 批量发送模板短信消息
     */
    @ApiOperation(value = "批量发送模板短信消息")
    @PostMapping("/batchSendMessageYhqfxx")
    public ResultRespone batchSendMessageYhqfxx(@RequestBody SmsMessageYhxxDto dto) {
        return ResultRespone.success(ISmsMessageService.batchSendMessageYhqfxx(dto));
    }

    /**
     * 发送模板短信消息
     */
    @ApiOperation(value = "发送模板短信消息")
    @PostMapping("/SendTxlxMessage")
    public ResultRespone SendTxlxMessage(@RequestBody SendTxlxMessageDto dto) {
        return ResultRespone.success(ISmsMessageService.SendTxlxMessage(dto));
    }

}
