package com.yunfeiyun.agmp.common.framework.web.domain;

import com.google.gson.Gson;
import com.yunfeiyun.agmp.common.constant.ResConstants;
import com.yunfeiyun.agmp.common.web.system.domain.SysRes;

import javax.servlet.http.HttpServletRequest;

public class UploadParam {
    String resId;
    String resMediatype;
    String resBiztype;
    String resBizPathKey;
    String resBusId;
    ResConstants.mediaType mediaType;
    ResConstants.BizType bizType;

    public String getResBusId() {
        return resBusId;
    }

    public void setResBusId(String resBusId) {
        this.resBusId = resBusId;
    }



    public String getResId() {
        return resId;
    }

    public void setResId(String resId) {
        this.resId = resId;
    }

    public String getResBizPathKey() {
        return resBizPathKey;
    }

    public void setResBizPathKey(String resBizPathKey) {
        this.resBizPathKey = resBizPathKey;
    }

    public String getResMediatype() {
        return resMediatype;
    }

    public void setResMediatype(String resMediatype) {
        this.resMediatype = resMediatype;
    }

    public String getResBiztype() {
        return resBiztype;
    }

    public void setResBiztype(String resBiztype) {
        this.resBiztype = resBiztype;
    }

    public ResConstants.mediaType getMediaType() {
        return mediaType;
    }

    public void setMediaType(ResConstants.mediaType mediaType) {
        this.mediaType = mediaType;
    }

    public ResConstants.BizType getBizType() {
        return bizType;
    }

    public void setBizType(ResConstants.BizType bizType) {
        this.bizType = bizType;
    }

    public static UploadParam parse(HttpServletRequest request){
        try {
            String UploadParam = request.getParameter("UploadParam");
            com.yunfeiyun.agmp.common.framework.web.domain.UploadParam uploadParam = new Gson().fromJson(UploadParam, UploadParam.class);
            if (uploadParam != null && uploadParam.getResMediatype() != null) {
                ResConstants.mediaType mediaType = ResConstants.mediaType.getKey(uploadParam.getResMediatype());
                if(mediaType != null){
                    uploadParam.setMediaType(mediaType);
                }else{
                    uploadParam.setMediaType(ResConstants.mediaType.VIDEO);
                }
            }
            if (uploadParam != null && uploadParam.getResBiztype() != null) {
                ResConstants.BizType bizType = ResConstants.BizType.getKey(uploadParam.getResBiztype());
                if(bizType != null){
                    uploadParam.setBizType(bizType);
                }else{
                    uploadParam.setBizType(ResConstants.BizType.TUTORIAL);
                }
            }
            String resBusId = uploadParam.getResBusId() == null || !SysRes.valid(uploadParam.getResBusId()) ? "-1" : uploadParam.getResBusId();
            uploadParam.setResBusId( resBusId );
            return uploadParam;
        }catch (Exception e){
            e.printStackTrace();
            return null;
        }finally {

        }

    }
}
