from json import dumps

from util.TimeUtils import now_date_to_str


def message_feedback(requestId, status, analyse_type, error_code="", error_msg="", progress="", original_url="",
                     sign_url="", modelCode="", detectTargetCode="", analyse_results="", video_url="", ai_video_url="",longitude="",latitude=""):
    if len(analyse_results) > 0:
        analyse_results = dumps(analyse_results)
    taskbar = {
        "request_id": requestId,
        "status": status,
        "type": analyse_type,
        "video_url": video_url,
        "ai_video_url": ai_video_url,
        "error_code": error_code,
        "error_msg": error_msg,
        "progress": progress,
        "results": [
            {
                "original_url": original_url,
                "sign_url": sign_url,
                "analyse_results": analyse_results,
                "model_code": modelCode,
                "detect_targets_code": detectTargetCode,
                "analyse_time": now_date_to_str(),
                "longitude":str(longitude),
                "latitude":str(latitude),
            }
        ]
    }
    return {"feedback": taskbar}


def recording_feedback(requestId, status, error_code="", error_msg="", progress="", video_url=""):
    rdf = {
        "request_id": requestId,
        "status": status,
        "error_code": error_code,
        "error_msg": error_msg,
        "progress": progress,
        "video_url": video_url
    }
    return {"recording": rdf}


def pull_stream_feedback(requestId, status, error_code="", error_msg="", videoInfo=[]):
    return {"pull_stream": {
        "request_id": requestId,
        "video_info_list": videoInfo,
        "push_stream_status": status,
        "error_code": error_code,
        "error_msg": error_msg,
        "current_time": now_date_to_str()
    }}
