package com.fdkankan.push.config;


import cn.hutool.core.date.DateUtil;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.fdkankan.push.android.*;
import com.fdkankan.push.common.PushClient;
import com.fdkankan.push.ios.*;
import lombok.extern.slf4j.Slf4j;

import java.util.Date;

@Slf4j
public class PushMessageConfig {
	private String appkey = null;
	private String appMasterSecret = null;
	private PushClient client = new PushClient();

	public static final String ANDROID_KEY = "5ee71c03dbc2ec076dd488cb";
	public static final String ANDROID_SECRET = "gzw4r8frbhq6eigxrvgjkdrm7wgtu83g";
	public static final String IOS_KEY = "5ee71ca9978eea081640f22a";
	public static final String IOS_SECRET = "tpuhyojch16pcha2qmpidlbnzkielv9w";

	//转台双目使用
	public static final String ANDROID_KEY_Z = "60efd777a6f90557b7b97c25";
	public static final String ANDROID_SECRET_Z = "ll85ov3qzeuas0ig7cw0v5bgzq1bdl07";
	public static final String IOS_KEY_Z = "60efd7c9a6f90557b7b97d10";
	public static final String IOS_SECRET_Z = "li62b5f3d9kn8idvy6qva3c5gyidmqwl";

	public PushMessageConfig(String key, String secret) {
		appkey = key;
		appMasterSecret = secret;
	}

	public String getAppkey() {
		return appkey;
	}

	public void setAppkey(String appkey) {
		this.appkey = appkey;
	}

	public String getAppMasterSecret() {
		return appMasterSecret;
	}

	public void setAppMasterSecret(String appMasterSecret) {
		this.appMasterSecret = appMasterSecret;
	}

	public void sendAndroidUnicast(String token, String ticker, String title, String text, String url) throws Exception {
		AndroidUnicast unicast = new AndroidUnicast(appkey,appMasterSecret);
		// TODO Set your device token
		unicast.setDeviceToken(token);
		unicast.setTicker(ticker);
		unicast.setTitle(title);
		unicast.setText(text);
		unicast.goUrlAfterOpen(url);
		unicast.setDisplayType(AndroidNotification.DisplayType.NOTIFICATION);
		// TODO Set 'production_mode' to 'false' if it's a test device. 
		// For how to register a test device, please see the developer doc.
		unicast.setProductionMode();
		// Set customized fields
		unicast.setExtraField("test", "helloworld");
		unicast.setChannelActivity("com.fdage.eight.module.EightPushMsgHandlerActivity");
//		unicast.setChannelProperties("abc");

		client.send(unicast);
	}

	//转台相机
	public void sendAndroidUnicast2(String token, String ticker, String title, String text, String url) throws Exception {
		AndroidUnicast unicast = new AndroidUnicast(appkey,appMasterSecret);
		// TODO Set your device token
		unicast.setDeviceToken(token);
		unicast.setTicker(ticker);
		unicast.setTitle(title);
		unicast.setText(text);
		unicast.goUrlAfterOpen(url);
		unicast.setDisplayType(AndroidNotification.DisplayType.NOTIFICATION);
		// TODO Set 'production_mode' to 'false' if it's a test device.
		// For how to register a test device, please see the developer doc.
		unicast.setProductionMode();
		// Set customized fields
		unicast.setExtraField("test", "helloworld");
		unicast.setChannelActivity("io.github.zileyuan.umeng_analytics_push.OfflineNotifyClickActivity");
//		unicast.setChannelProperties("abc");

		client.send(unicast);
	}
	
	public void sendIOSUnicast(String token, String title ,String subtitle , String body, String url) throws Exception {
		IOSUnicast unicast = new IOSUnicast(appkey,appMasterSecret);
		// TODO Set your device token
		unicast.setDeviceToken(token);
		//alert值设置为字符串
		//unicast.setAlert("IOS 单播测试");
		//alert的值设置为字典
		unicast.setAlert(title, subtitle, body, url);
//		unicast.setBadge( 0);
		unicast.setSound( "default");
		// TODO set 'production_mode' to 'true' if your app is under production mode
		unicast.setProductionMode();
//		unicast.setTestMode();
		unicast.setDescription(title);
		unicast.setExpireTime(DateUtil.formatTime(DateUtil.offsetDay(new Date(), 1)));
		// Set customized fields
//		unicast.setCustomizedField("url", url);
		client.send(unicast);
	}
}
