//
//  PQSingletonEnvUtil.swift
//  PQSpeed
//
//  Created by lieyunye on 2020/5/27.
//  Copyright © 2020 BytesFlow. All rights reserved.
//

import Foundation
import KeychainAccess
import BFCommonKit

// add by ak 开发和发布版本的不同设置  1 为正式版本发布的苹果  0 是测试 XXXX 上传苹果前要检查
public let DEVELOPMENT_ENVIRONMENT: Int = 1

public enum ENVMode: String {
    case ENVModeOnline // 线上环境
    case ENVModePre // 预发布环境
    case ENVModeTest // 测试环境
    case ENVModeBJPre // 北京区预发布环境
}

public class PQENVUtil {
    public var envMode: ENVMode {
        let config = NSDictionary(contentsOfFile: Bundle.main.path(forResource: "PQConfig.plist", ofType: nil) ?? "")
        BFLog(message: "config  is  = \(String(describing: config))")

        let enStr: String = (config?.object(forKey: "ENVMode") ?? "ENVModeOnline") as! String
        BFLog(message: "ENVMode is \(enStr)")

        return ENVMode(rawValue: enStr)!
    }

     static public let shared: PQENVUtil = {
        let instance = PQENVUtil()
        // setup code

        return instance
    }()

    // 票圈视频主域名
   public var longvideoapi: String {
        switch envMode {
        case .ENVModeTest:
            return testLongvideoapi
        case .ENVModePre:
            return preLongvideoapi
        case .ENVModeBJPre:
            return preBJLongvideoapi
        default:
            return onlineLongvideoapi
        }
    }

    // 通用域名-eg：数据上报
    public var commonapi: String {
        switch envMode {
        case .ENVModeTest:
            return testCommonapi
        case .ENVModePre:
            return preCommonapi
        case .ENVModeBJPre:
            return preBJCommonapi
        default:
            return onlineCommonapi
        }
    }

    // 视频创作相关域名
    public var clipapiapi: String {
        switch envMode {
        case .ENVModeTest:
            return testLongvideoapi
        case .ENVModePre, .ENVModeBJPre:
            return preLongvideoapi
        default:
            return onlineClipapiApi
        }
    }

    // 创作工具搜索素材相关域名
    public var materialSearchApi: String {
        switch envMode {
        case .ENVModeTest:
            return testMaterialSearchApi
        case .ENVModePre, .ENVModeBJPre:
            return preMaterialSearchApi
        default:
            return onlineMaterialSearchApi
        }
    }

    // 消息相关域名
    public var messageApi: String {
        switch envMode {
        case .ENVModeTest:
            return testMessageApi
        case .ENVModePre, .ENVModeBJPre:
            return preMessageApi
        default:
            return onlineMessageApi
        }
    }
    // 票圈Api域名
    public var pqTvApi: String {
        switch envMode {
        case .ENVModeTest:
            return testPQTvApi
        case .ENVModePre, .ENVModeBJPre:
            return prePQTvApi
        default:
            return onlinePQTvApi
        }
    }
}
