package com.yeejoin.amos.patrol.feign;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

import com.yeejoin.amos.patrol.business.param.PushMsgParam;
import com.yeejoin.amos.patrol.business.util.CommonResponse;
import com.yeejoin.amos.patrol.business.util.CommonResponseUtil;
import com.yeejoin.amos.patrol.core.common.response.TaskInfoRespone;
import com.yeejoin.amos.feign.systemctl.Systemctl;
import com.yeejoin.amos.feign.systemctl.model.MessageModel;

@Service("pushFeignServer")
public class PushFeignServer {
//	 @Autowired
//	    private RestTemplate restTemplate;
//	
//	    @Value("${Push.fegin.name}")
//	    private String RPushFeginName;
//	    private static String sendMessage = "/api/user/sendMessage";
//	    
//	    public  String geturls(String url){
//	    	return "http://"+RPushFeginName+url;
//	    }
//	    public  HttpHeaders getHeader(String toke,String product,String appKey){
//	    	HttpHeaders headers = new HttpHeaders();
//		    headers.setContentType(MediaType.APPLICATION_JSON);
//		    headers.set("Content-Type", "application/json");  
//		    headers.set("token", toke);
//		    headers.set("product",product);
//		    headers.set("appKey", appKey);
//		    return headers;
//	    } 
	    
	    public void sendMessage( String toke,String product,String appKey, List<PushMsgParam> pushMsgParam){
			 try {
				    pushMsgParam.forEach(action->{
				    	sendJP(action);
				    });
				} catch (Exception e) {
					e.printStackTrace();	 
				}
		}
	    
	    public void sendMessage( String toke,String product,String appKey, PushMsgParam pushMsgParam){
			 try {
				 sendJP(pushMsgParam);
				} catch (Exception e) {
					e.printStackTrace();	 
				}
		}
	    
	    private void sendJP(PushMsgParam pushMsgParam){
	    	MessageModel model = new MessageModel();
	    	model.setRelationId(pushMsgParam.getRelationId());
	    	model.setTitle(pushMsgParam.getSubject());
	    	model.setBody(pushMsgParam.getContent());
	    	model.setMsgType("patrolSystem");
	    	model.setRecivers(pushMsgParam.getRecivers());
	    	model.setExtras(pushMsgParam.getExtras());
		    Systemctl.messageClient.create(model);
	    }
}
