package com.nokia.alarm.service;

import java.util.HashMap;
import java.util.Map;

import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

import com.fasterxml.jackson.databind.JsonNode;

import lombok.extern.slf4j.Slf4j;

@Slf4j
@Service
public class SmsSendService {

    private final RestTemplate restTemplate = new RestTemplate();
    private final String url = "http://192.168.70.125:12080/api/sms/sendByPhoneNumber";

    public void send(String phoneNumber, String content) {
        Map<String, Object> request = new HashMap<>();
        request.put("phoneNumber", phoneNumber);
        request.put("content", content);
        request.put("fromSystem", "SmsAlarmReport");
        request.put("smsType", "SmsAlarmReport");
        request.put("internalId", "000001");
        JsonNode jsonNode = restTemplate.postForObject(url, request, JsonNode.class);
        log.info("send message to {}: {}", phoneNumber, jsonNode);
    }

    public void send(String[] phoneNumbers, String content) {
        for (String phoneNumber : phoneNumbers) {
            send(phoneNumber, content);
        }
    }
}
