package com.platform.modules.live.constants;

import com.alibaba.druid.util.StringUtils;
import com.aliyuncs.http.MethodType;

import java.util.Arrays;

/**
 * @Description:
 * @Author: yikaihong
 * @CreateDate: 2019/1/19 15:12
 * @Version: 1.0
 */
public interface LiveConstants {


    /**
     * restful 请求映射
     */
    enum RequestMethod {
        POST("post", MethodType.POST),
        GET("get", MethodType.GET),
        PUT("put", MethodType.PUT),
        DELETE("delete", MethodType.DELETE);
        private String requestMethodStr;
        private MethodType methodType;

        RequestMethod(String requestMethodStr, MethodType methodType) {
            this.requestMethodStr = requestMethodStr;
            this.methodType = methodType;
        }

        /**
         * 获取请求枚举
         *
         * @param requestMethodStr
         * @return
         */
        public static MethodType getMethodType(String requestMethodStr) {
            if (StringUtils.isEmpty(requestMethodStr)) {
                return POST.getMethodType(); // 默认post
            }
            final RequestMethod[] requestMethod = new RequestMethod[1];
            Arrays.asList(RequestMethod.values()).stream()
                    .forEach(item -> {
                        if (item.getRequestMethodStr().equals(requestMethodStr)) {
                            requestMethod[0] = item;
                            return;
                        }
                    });
            return requestMethod[0] == null ? POST.getMethodType() : requestMethod[0].getMethodType();
        }

        public MethodType getMethodType() {
            return methodType;
        }

        public String getRequestMethodStr() {
            return requestMethodStr;
        }

        public void setMethodType(MethodType methodType) {
            this.methodType = methodType;
        }

        public void setRequestMethodStr(String requestMethodStr) {
            this.requestMethodStr = requestMethodStr;
        }
    }

    interface ServiceType {
        /**
         * 录制
         */
        Integer RECORD = 1;
        /**
         * 上传
         */
        Integer UPLOAD = 2;
        /**
         * 合成
         */
        Integer PRODUCE = 3;
    }

    interface TranscodeStatus {
        /**
         * 上传中
         */
        Integer UPLOADING = 0;
        /**
         * 转码中
         */
        Integer TRANSCODEING = 1;
        /**
         * 转码成功
         */
        Integer TRANSCODE_SUCCESS = 2;
        /**
         * 转码失败
         */
        Integer TRANSCODE_FAIL = 3;
    }

    interface RecordType {
        /**
         * 直播时移
         */
        Integer FAST_RECORD = 0;
        /**
         * m3u8
         */
        Integer M3U8_RECORD = 1;
        /**
         * mp4
         */
        Integer MP4_RECORD = 2;
        /**
         * 快速剪辑
         */
        Integer CLIP_RECORD = 3;
        /**
         * mp3
         */
        Integer MP3_RECORD = 4;
    }
}