package com.sckw.message.controller;

import cn.hutool.core.lang.UUID;
import com.alibaba.fastjson2.JSON;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.sckw.core.web.response.HttpResult;
import com.sckw.stream.enums.SmsCodeEnum;
import com.sckw.stream.model.Person;
import com.sckw.message.producer.DelayProducer;
import com.sckw.stream.enums.MessageEnum;
import com.sckw.stream.model.SckwMessage;
import com.sckw.stream.model.SckwSms;
import jakarta.annotation.Resource;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.stream.function.StreamBridge;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.HashMap;

/**
 * 测试mq
 */
@Slf4j
@RestController
@AllArgsConstructor
@RequestMapping("/test-mq")
public class TestMqController {

    private final DelayProducer delayProducer;

    @GetMapping("/index")
    public HttpResult index() {
        return HttpResult.ok(System.currentTimeMillis());
    }


    /**
     * 发送消息Rabbitmq
     * @param msg 消息内容
     * @param delay 延时时间
     */
    @GetMapping("/sendRabbitmq")
    public HttpResult sendRabbitmq(String msg, Long delay) {
        delayProducer.sendMsg(msg, delay);
        return HttpResult.ok();
    }

    @Resource
    private StreamBridge streamBridge;
    @Autowired
    private ObjectMapper objectMapper;

    @GetMapping("/sendTest")
    public HttpResult sendRabbitMq(String name) {
        String uuid = UUID.fastUUID().toString();
        SckwSms sckwSms = new SckwSms();
        sckwSms.setPhone("17358629955");
        sckwSms.setSignName("矿拉拉");
        sckwSms.setTemplateCode(SmsCodeEnum.VERIFICATION_CODE);
        sckwSms.setParams(new HashMap(){{put("code", "123456");}});
        streamBridge.send("sckw-sms", JSON.toJSONString(sckwSms));


        SckwMessage message = new SckwMessage();
        //person.setName(String.valueOf(System.currentTimeMillis()));
        message.setMsgUrl("---");
        message.setPushType("====");
        message.setClientId("111111111111111");
        streamBridge.send("sckw-message", JSON.toJSONString(message));
        return HttpResult.ok(uuid);

    }


}
