package com.qimai.log

import android.content.Intent
import com.tencent.mars.xlog.Log

object QmLog {

    fun d(tag: String, message: String) {
        Log.d(tag, message)
    }

    fun e(tag: String, message: String) {
        Log.e(tag, message)
    }

    fun v(tag: String, message: String) {
        Log.v(tag, message)
    }

    fun w(tag: String, message: String) {
        Log.w(tag, message)
    }

    fun i(tag: String, message: String) {
        Log.i(tag, message)
    }

    fun flush() {
        Log.appenderClose()
    }

    /**
     * 上传log
     */
    fun uploadLog(config: UploadConfig) {
        //刷新下
        Log.appenderFlush(false)
        val intent = Intent(getConfig().app, UploadService::class.java)
        intent.putExtra("upload", config)
        getConfig().app.startService(intent)
    }
    fun uploadLog(config: UploadConfig,callBack: UploadCallBack) {
        //刷新下
        Log.appenderFlush(false)
        FtpUpload.upload(config,callBack)
    }
    fun getConfig(): QmLogConfig {
        val config: QmLogConfig? = LogInit.getInstance().getConfig()
        if (config == null) {
            throw IllegalArgumentException("please call LogInit.init() first")
        } else {
            return config
        }
    }

    //上传log
    /***
     * filePath 保存logo的路径
     */
    fun uploadXog(config: (filePath: String) -> Unit) {
        //刷新下
        Log.appenderFlush(false)
        // final String logPath = SDCARD + "/ptcy/log";
        val logPath: String = if (BuildConfig.DEBUG) {
            getConfig().logDebugPath
        } else {
            getConfig().logReleasePath
        }
        config(logPath)
        // val intent = Intent(getConfig().app, UploadService::class.java)
        // getConfig().app.startService(intent)
    }
}