export module BusinessEnum {
    export enum BusinessType {
        Type1 = "H5",
        Type2 = "App"
    }
    export enum ServerType {
        /** WEB格式 */
        Web = 1,
        /** 外版 */
        Out = 2,
        /** 送審環境 */
        Submit = 3,
        /** 內版商業DEMO測試(B2B) */
        Internal_release = 4,
        /** 內版開發(內網&4G) */
        Internal_Dev = 5,
        /** 外部商業DEMO(B2B) */
        Out_B2B = 6
    }
    export enum LogoType {
        /** 完美(目前只有WEB) */
        WM = 1
    }
}

/**
產品商業類別設定檔
@explain 讀不同表就代表不同商業類別.要多開GIT並設定新測試環境
@explain 遊戲一定都一樣不能改動介面
 */
export default class BusinessTypeSetting {
    /** 產品商業類別字串(組合判斷用) */
    public static readonly TYPE_BUSINESS: string = "App";
    /** 編譯版本 */
    public static readonly COMPILE_VERSION: string = "1.4.1";
    /** 編譯程式碼版號 */
    public static readonly SCRIPT_BUNLE_LIST: string[] = [
        "FormTableScript", "CommonScript", "ElementUIScript", "LoginScript", "LobbyScript", "SlotScript"
    ];
    public static readonly ART_UI_BUNLE_LIST: string[] = [
        "Common", "CommonSound", "Login", "Lobby", "GameCommon",
        "Game_BottomUI_SD", "Game_BigWinJackpot", "GameMessage", "CommonLanguageTexture", "MainControl",
        "BindAccount", "SettingPanel", "Shop", "Vip", "Ad",
        "Mail", "Chat", "PlayerInfo", "Rank", "Gift",
        "ResourceItem", "Backpack", "GettingPanel", "Activity", "Game_BottomUI_BJ"
    ];
    public static readonly DEV_ART_UI_BUNLE_LIST: string[] = [

    ]
    public static readonly ART_GAME_BUNLE_LIST: string[] = [
        "Game_1201", "Game_1202", "Game_1302"
    ]
    public static readonly ART_REMOTE_GAME_BUNLE_LIST: string[] = [
        "Game_1", "Game_2", "Game_5", "Game_8", "Game_9",
        "Game_10", "Game_12", "Game_15", "Game_16", "Game_18",
        "Game_23", "Game_24", "Game_25", "Game_26", "Game_27",
        "Game_28", "Game_29", "Game_30", "Game_32", "Game_33",
        "Game_34", "Game_35", "Game_37", "Game_36", "Game_40",
        "Game_44", "Game_48", "Game_50", "Game_51", "Game_58",
        "Game_1101", "Game_1401", "Game_1501", "Game_2001", "Game_2003",
        "Game_3002", "Game_3003", "Game_3012",
    ]
    /** 送審旗標(讀取外版自動判斷是否送審) */
    public static IsSubmit: boolean = false;
    /** 跑送審2的手動旗標(若是送審且設為true跑2號環境) */
    public static IsSubmitTestFlight: boolean = false;
    /** B2B手動旗標(true寫死B2B環境) */
    public static IsB2B: boolean = false;

    /** 商業LOGO圖代碼(讀同一張表但UI有改的設定) */
    public static Logo: number = null!;
    /** 連線IP(網頁版會接網址參數所以要多開變數直接指定) */
    public static UseHost: string = null!;
    /** 連接阜(網頁版會接網址參數所以要多開變數直接指定) */
    public static UsePort: number = null!;
    /** 資源伺服器網址 */
    public static UsePatch: string = null!;
    /** 帳號 */
    public static Account: string = null!;
    /** 密碼 */
    public static Password: string = null!;

    // =======================================================================================
    /** 執行環境ProductEnum.ServerType */
    public static UseServerTpye: BusinessEnum.ServerType = BusinessEnum.ServerType.Web;
    /** 網頁是否在伺服器上 */
    public static readonly CheckOnServer: boolean =
        window.location.href.indexOf("localhost") == -1
        && window.location.href.indexOf("/build/") == -1;
    /** 網頁測試讀取對應資源的位置 */
    public static readonly FolderUrlImg: string = "shared/img/";
    public static readonly FolderUrlBg: string = "shared/bg/";
    public static readonly FolderUrlJson: string = "shared/jsons/";
    public static readonly FolderUrlTxt: string = "shared/txt/";
    public static readonly FolderUrlLoading: string = "shared/loading/";
    public static readonly FolderUrlMp3: string = "shared/";
    public static readonly FolderUrlBundle: string = `Bundle_${true ? "Debug" : "Release"}/`;
    public static readonly FolderOS: string = "Android/";
    /**遠端Bundle路徑為: URL + BundleName.非遊戲資源到各自平台資料夾找BUNDLE */
    public static GetRemoteFileUrl(bundleName: string): string {
        let gameNumber: string = bundleName.split("Game_")[1];
        var regExp: RegExp = /^[0-9]+$/;
        let isGame: boolean = regExp.test(gameNumber);
        let bundleUrl: string = `${BusinessTypeSetting.UsePatch}${BusinessTypeSetting.FolderUrlBundle}`;
        if (isGame) {
            bundleUrl = `${bundleUrl}${bundleName}`;
        } else {
            bundleUrl = `${bundleUrl}${BusinessTypeSetting.FolderOS}${bundleName}`;
        }
        return bundleUrl;
    }
    /**
     * 取得PACH資原路徑
     * @param type 執行環境()
     * @returns
     */
    public static GetPatchUrl(type: BusinessEnum.ServerType): string {
        if (this.UseServerTpye == BusinessEnum.ServerType.Web) {
            // TYP2網頁版資源路路徑判斷
            if (this.CheckOnServer) {
                return "../shared/";
            } else {
                return "http://patch-dev.online-bj.com//shared/";
            }
        }
        switch (type) {
            case BusinessEnum.ServerType.Out:
                return "https://patch.online-bj.com/game/";
            case BusinessEnum.ServerType.Submit:
                if (!this.IsSubmitTestFlight) {
                    return "https://patch-submit.online-bj.com/game/";
                } else {
                    return "https://patch-submit2.online-bj.com/game/";
                }

            case BusinessEnum.ServerType.Out_B2B:
                return "https://patch-demo.online-bj.com/game/";
            case BusinessEnum.ServerType.Internal_release:
                return "http://patch-release.online-bj.com/";

            case BusinessEnum.ServerType.Internal_Dev:
                return "http://patch-dev.online-bj.com/";

            default:
                console.warn("GetPatchUrl Uncheck ServerType.");
                return "http://patch-dev.online-bj.com/";
        }
    }
    /**
     * 取得連線伺服器IP
     * @param type 執行環境
     * @returns
     */
    public static GetHostUrl(type: BusinessEnum.ServerType): string {
        if (this.UseServerTpye == BusinessEnum.ServerType.Web) {
            return "app.casino.catan.com.tw";
        }
        switch (type) {
            case BusinessEnum.ServerType.Out:
                return "https://game.online-bj.com";
            case BusinessEnum.ServerType.Submit:
                if (!this.IsSubmitTestFlight) {
                    return "https://submit.online-bj.com";
                } else {
                    return "https://submit2.online-bj.com";
                }

            case BusinessEnum.ServerType.Out_B2B:
                return "https://demo.online-bj.com";
            case BusinessEnum.ServerType.Internal_release:
                return "https://demo.online-bj.com";

            case BusinessEnum.ServerType.Internal_Dev:
                return "http://220.134.195.1";

            default:
                console.warn("GetHostUrl Uncheck ServerType.");
                // 只有內網可憐IP
                return "app.casino.catan.com.tw";
        }
    }
    /**
     * 取得伺服器連接端口
     * @param type 執行環境
     * @returns
     */
    public static GetPortNum(type: BusinessEnum.ServerType): number {
        if (this.UseServerTpye == BusinessEnum.ServerType.Web) {
            // 網頁版測試專用.正式接網頁參數
            return 9005;
        }
        switch (type) {
            case BusinessEnum.ServerType.Out:
                return 9005;
            case BusinessEnum.ServerType.Submit:
                if (!this.IsSubmitTestFlight) {
                    return 9005;
                } else {
                    return 9005;
                }

            case BusinessEnum.ServerType.Out_B2B:
                return 9005;
            case BusinessEnum.ServerType.Internal_release:
                return 9005;

            case BusinessEnum.ServerType.Internal_Dev:
                return 19005;

            default:
                console.warn("GePortNum Uncheck ServerType.");
                return 9005;
        }
    }
    public static GetDownloadUrl(type: BusinessEnum.ServerType): string {
        switch (type) {
            case BusinessEnum.ServerType.Internal_Dev:
                return "http://static-dev.online-bj.com/";
            default:
                let url: string = this.GetHostUrl(type);
                url = url.replace("http://", "");
                url = url.replace("https://", "");
                return "https://static-" + url;
        }
    }

    public static GetUploadUrl(type: BusinessEnum.ServerType): string {
        let port: string = ":9080";
        switch (type) {
            case BusinessEnum.ServerType.Internal_Dev:
                return "http://static-dev.online-bj.com" + port;
            default:
                return this.GetHostUrl(type) + port;
        }
    }
    // =======================================================================================
}