using System;
using System.Collections.Generic;
using Unity.Plastic.Newtonsoft.Json;
using UnityEngine;

public class BuildParams
{
    //版本号
    public string AppVersion = "";

    //资源版本号
    public string ResVersion = "";

    //build 
    public string BuildVersion = "";

    //平台
    public string Platform = "";

    //打包类型
    public string BuildType = "";

    //是否Relase 或者 debug
    public string Mode = "";

    //CDN输出源
    public string ResourceRoot = "";

    public void Description()
    {
        Debug.Log("AppVersion = " + AppVersion);
        Debug.Log("BuildVersion = " + BuildVersion);
        Debug.Log("Platform = " + Platform);
        Debug.Log("BuildType = " + BuildType);
        Debug.Log("Mode = " + Mode);
        Debug.Log("ResourceRoot = " + ResourceRoot);
    }
}

public static class BuildParamsHelper
{
    /// <summary>
    /// 根据jenkins的参数读取到BuildParams里
    /// </summary>
    /// <returns></returns>
    public static BuildParams GetBuildParams()
    {
        string[] parameters = Environment.GetCommandLineArgs();
        BuildParams BuildParams = new BuildParams();
        foreach (string str in parameters)
        {
            if (str.StartsWith("AppVersion"))
            {
                var tempParam = str.Split(new string[] { "=" }, StringSplitOptions.RemoveEmptyEntries);
                if (tempParam.Length == 2)
                {
                    BuildParams.AppVersion = tempParam[1].Trim();
                }
            }
            else if (str.StartsWith("BuildVersion"))
            {
                var tempParam = str.Split(new string[] { "=" }, StringSplitOptions.RemoveEmptyEntries);
                if (tempParam.Length == 2)
                {
                    BuildParams.BuildVersion = tempParam[1].Trim();
                }
            }
            else if (str.StartsWith("ResVersion"))
            {
                var tempParam = str.Split(new string[] { "=" }, StringSplitOptions.RemoveEmptyEntries);
                if (tempParam.Length == 2)
                {
                    BuildParams.ResVersion = tempParam[1].Trim();
                }
            }
            else if (str.StartsWith("Platform"))
            {
                var tempParam = str.Split(new string[] { "=" }, StringSplitOptions.RemoveEmptyEntries);
                if (tempParam.Length == 2)
                {
                    BuildParams.Platform = tempParam[1].Trim();
                }
            }
            else if (str.StartsWith("BuildType"))
            {
                var tempParam = str.Split(new string[] { "=" }, StringSplitOptions.RemoveEmptyEntries);
                if (tempParam.Length == 2)
                {
                    BuildParams.BuildType = tempParam[1].Trim();
                }
            }
            else if (str.StartsWith("Mode"))
            {
                var tempParam = str.Split(new string[] { "=" }, StringSplitOptions.RemoveEmptyEntries);
                if (tempParam.Length == 2)
                {
                    BuildParams.Mode = tempParam[1].Trim();
                }
            }
            else if (str.StartsWith("ResourceRoot"))
            {
                var tempParam = str.Split(new string[] { "=" }, StringSplitOptions.RemoveEmptyEntries);
                if (tempParam.Length == 2)
                {
                    BuildParams.ResourceRoot = tempParam[1].Trim();
                }
            }
        }

        return BuildParams;
    }
}