package com.sckw.message.controller;

import com.sckw.core.web.response.HttpResult;
import com.sckw.message.model.bo.*;
import com.sckw.message.service.SmsService;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;


@RestController
@RequestMapping(value = "/kwmSms")
@RequiredArgsConstructor
public class SmsController {

    private final SmsService smsService;

    /**
     * 发送验证码
     * @param smsBo
     * @return
     */
    @PostMapping(value = "/sendVerifyCode", produces = MediaType.APPLICATION_JSON_VALUE)
    public HttpResult sendVerifyCode(@Valid @RequestBody SmsBo smsBo) {
        smsService.sendVerifyCode(smsBo);
        return HttpResult.ok();
    }


    @PostMapping(value = "/send", produces = MediaType.APPLICATION_JSON_VALUE)
    public HttpResult sendSms(@Valid @RequestBody SmsBo smsBo) {
        smsService.sendSms(smsBo);
        return HttpResult.ok();
    }

    @PostMapping(value = "/batchSend", produces = MediaType.APPLICATION_JSON_VALUE)
    public HttpResult batchSendSms(@Valid @RequestBody BatchSendSmsBo batchSendSmsBo) {
        smsService.batchSendSms(batchSendSmsBo);
        return HttpResult.ok();
    }

    @PostMapping(value = "/record/page", produces = MediaType.APPLICATION_JSON_VALUE)
    public HttpResult pageRecord(@RequestBody SmsRecordQueryBo queryBo) {
        return HttpResult.ok(smsService.pageRecord(queryBo));
    }

    @GetMapping(value = "/record/{id}", produces = MediaType.APPLICATION_JSON_VALUE)
    public HttpResult getRecordDetail(@PathVariable Long id) {
        return HttpResult.ok(smsService.getRecordDetail(id));
    }

    @PostMapping(value = "/template/page", produces = MediaType.APPLICATION_JSON_VALUE)
    public HttpResult pageTemplate(@RequestBody SmsTemplateQueryBo queryBo) {
        return HttpResult.ok(smsService.pageTemplate(queryBo));
    }

    @GetMapping(value = "/template/{id}", produces = MediaType.APPLICATION_JSON_VALUE)
    public HttpResult getTemplateDetail(@PathVariable Long id) {
        return HttpResult.ok(smsService.getTemplateDetail(id));
    }

}
