package cn.com.wasu.main.systeminfo;

import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;

import com.wasu.authsdk.AuthSDK;
import com.wasu.authsdk.IAuthInterface;

import java.util.ArrayList;
import java.util.List;

import basic.BuilderTypeManager.BuildType;
import basic.api.API_UPDATE;

public class AppInfo {
	
	private Context mContext = null;
	private PackageManager packageManager = null;
	
	public AppInfo(Context context) {
		mContext = context;
		packageManager = mContext.getPackageManager();
	}
	
	/**
	 * 获取应用名称
	 * @return
	 */
	private String getProjectName() {
		ApplicationInfo applicationInfo = null;
		try {
			applicationInfo = packageManager.getApplicationInfo(mContext.getPackageName(), 0);
		} catch (NameNotFoundException e) {
			e.printStackTrace();
		}
		return "项目名称：" + packageManager.getApplicationLabel(applicationInfo);
	}
	
	/**
	 * 获取应用版本名称
	 * @return
	 */
	private String getAppVersionName() {
		PackageInfo packageInfo = null;
		try {
			packageInfo = packageManager.getPackageInfo(mContext.getPackageName(), 0);
		} catch (NameNotFoundException e) {
			e.printStackTrace();
		}
		return "版本名称：" + packageInfo.versionName;
	}
	
	/**
	 * 获取应用版本号
	 * @return
	 */
	private String getAppVersionCode() {
		PackageInfo packageInfo = null;
		try {
			packageInfo = packageManager.getPackageInfo(mContext.getPackageName(), 0);
		} catch (NameNotFoundException e) {
			e.printStackTrace();
		}
		return "版本号：" + packageInfo.versionCode;
	}
	
	/**
	 * 获取TVID
	 * @return
	 */
	private String getTVID() {
		return "TVID：" + AuthSDK.getInstance().getValue(IAuthInterface.KEY_TVID);
	}
	
	private String getDeviceID() {
		return "DeviceID: " + AuthSDK.getInstance().getValue(IAuthInterface.KEY_DEVICEID);
	}
	
	/**
	 * 获取UserKey
	 * @return
	 */
	private String getUserKey() {
		return "UserKey：" + AuthSDK.getInstance().getValue(IAuthInterface.KEY_USERKEY);
	}
	
	/**
	 * 获取主页域名
	 * @return
	 */
	private String getHomeDomain() {
		return "主页域名：" + BuildType.HTTP_DOMAIN;
	}
	
	/**
	 * 获取升级接口地址
	 * @return
	 */
	private String getUpdateUrl() {
		return "升级接口地址：" + API_UPDATE.API_URL_UPDATE;
	}
	
	/**
	 * 获取升级信息
	 * @return
	 */
	private String getUpdateInfo() {
		return "升级信息：" + BuildType.UPDATE_INFO;
	}
	
	private String getSiteIdInfo(){
		return "站点ID: " + BuildType.SITE_ID;
	}
	
	private String getUpmInfo(){
		return "upm登录地址: " + BuildType.ManageUrl;
	}
	
	public List<String> getAppInfo() {
		ArrayList<String> appInfos = new ArrayList<String>();
		appInfos.add(this.getProjectName());
		appInfos.add(this.getAppVersionName());
		appInfos.add(this.getAppVersionCode());
		appInfos.add(this.getTVID());
		appInfos.add(this.getSiteIdInfo());
		appInfos.add(this.getUpmInfo());
		appInfos.add(this.getDeviceID());
		appInfos.add(this.getUserKey());
		appInfos.add(this.getHomeDomain());
		appInfos.add(this.getUpdateUrl());
		appInfos.add(this.getUpdateInfo());
		return appInfos;
	}
}
