package com.qmth.distributed.print.api;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.qmth.boot.api.constant.ApiConstant;
import com.qmth.distributed.print.business.bean.result.EditResult;
import com.qmth.distributed.print.business.entity.BasicMessage;
import com.qmth.distributed.print.business.enums.MessageEnum;
import com.qmth.distributed.print.business.service.BasicMessageService;
import com.qmth.distributed.print.business.service.PrintCommonService;
import com.qmth.distributed.print.business.templete.execute.AsyncCourseDataImportService;
import com.qmth.teachcloud.common.bean.params.BasicCourseParams;
import com.qmth.teachcloud.common.contant.SystemConstant;
import com.qmth.teachcloud.common.entity.BasicCourse;
import com.qmth.teachcloud.common.entity.SysUser;
import com.qmth.teachcloud.common.entity.TBTask;
import com.qmth.teachcloud.common.enums.EnumResult;
import com.qmth.teachcloud.common.enums.TaskTypeEnum;
import com.qmth.teachcloud.common.service.BasicCourseService;
import com.qmth.teachcloud.common.util.Result;
import com.qmth.teachcloud.common.util.ResultUtil;
import com.qmth.teachcloud.common.util.ServletUtil;
import com.sun.org.apache.xpath.internal.operations.Bool;
import io.swagger.annotations.*;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.validation.Valid;
import javax.validation.constraints.Max;
import javax.validation.constraints.Min;
import java.awt.*;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.stream.Collectors;

/**
 * <p>
 * 短信发送日志 前端控制器
 * </p>
 *
 * @author xf
 */
@Api(tags = "短信发送日志Controller")
@RestController
@RequestMapping(ApiConstant.DEFAULT_URI_PREFIX + "/${prefix.url.basic}/message")
@Validated
public class BasicMessageController {

    @Resource
    private BasicMessageService basicMessageService;

    /**
     * 查询短信类型
     *
     * @return
     */
    @ApiOperation(value = "查询短信类型")
    @RequestMapping(value = "/list_message_types", method = RequestMethod.POST)
    public Result listType() {
        List<EnumResult> list = basicMessageService.listMessageTypes();
        return ResultUtil.ok(list);
    }

    /**
     * 查询
     *
     * @param messageType
     * @param pageNumber
     * @param pageSize
     * @return
     */
    @ApiOperation(value = "查询")
    @RequestMapping(value = "/list", method = RequestMethod.POST)
    public Result list(@RequestParam(value = "messageType", required = false) MessageEnum messageType,
                       @RequestParam(value = "sendStatus", required = false) Boolean sendStatus,
                       @RequestParam(value = "mobileNumber", required = false) String mobileNumber,
                       @RequestParam @Min(SystemConstant.PAGE_NUMBER_MIN) Integer pageNumber,
                       @RequestParam @Min(SystemConstant.PAGE_SIZE_MIN) @Max(SystemConstant.PAGE_SIZE_MAX) Integer pageSize) {
        IPage<BasicMessage> messageIPage = basicMessageService.listByMessageType(messageType, sendStatus, mobileNumber, pageNumber, pageSize);
        return ResultUtil.ok(messageIPage);
    }

    /**
     * 短信失败重发
     *
     * @param id
     * @return
     */
    @ApiOperation(value = "短信失败重发")
    @RequestMapping(value = "/resend", method = RequestMethod.POST)
    public Result list(@RequestParam(value = "id", required = false) Long id) {
        basicMessageService.resendSmsTaskById(id);
        return ResultUtil.ok(true, null);
    }
}

