package com.cooleshow.teacher.widgets.helper;

import cn.rongcloud.beauty.RCRTCBeautyEngine;
import cn.rongcloud.beauty.RCRTCBeautyFilter;
import cn.rongcloud.beauty.RCRTCBeautyOption;

/**
 * Author by pq, Date on 2022/6/11.
 */
public class LiveRoomBeautyHelper {
    private volatile static LiveRoomBeautyHelper mHelper;
    public static final int OPTIONS_TYPE1 = 0;//美白
    public static final int OPTIONS_TYPE2 = 1;//磨皮
    public static final int OPTIONS_TYPE3 = 2;//红润
    public static final int OPTIONS_TYPE4 = 3;//亮度
    public static final int FILTER_TYPE_NONE = 5;//无滤镜
    public static final int FILTER_TYPE1 = 6;//唯美
    public static final int FILTER_TYPE2 = 7;//清新
    public static final int FILTER_TYPE3 = 8;//浪漫
    private int currentType = OPTIONS_TYPE1;//默认选择
    private int currentFilterType = FILTER_TYPE_NONE;//默认选择无滤镜

    private int beauty_whiteness_progress = 0;//美白参数
    private int beauty_smooth_progress = 0;//磨皮参数
    private int beauty_ruddy_progress = 0;//红润参数
    private int beauty_bright_progress = 0;//亮度参数

    private boolean isOpenBeauty = true;//是否开启美颜

    private LiveRoomBeautyHelper() {
    }


    public static LiveRoomBeautyHelper getInstance() {
        if (mHelper == null) {
            synchronized (LiveRoomBeautyHelper.class) {
                if (mHelper == null) {
                    mHelper = new LiveRoomBeautyHelper();
                }
            }
        }
        return mHelper;
    }

    public void update(int progress) {
        RCRTCBeautyOption beautyOption = RCRTCBeautyEngine.getInstance().getCurrentBeautyOption();
        if (currentType == OPTIONS_TYPE1) {
            beauty_whiteness_progress = progress;
            beautyOption.setWhitenessLevel(beauty_whiteness_progress);
        } else if (currentType == OPTIONS_TYPE2) {
            beauty_smooth_progress = progress;
            beautyOption.setSmoothLevel(beauty_smooth_progress);
        } else if (currentType == OPTIONS_TYPE3) {
            beauty_ruddy_progress = progress;
            beautyOption.setRuddyLevel(beauty_ruddy_progress);
        } else if (currentType == OPTIONS_TYPE4) {
            beauty_bright_progress = progress;
            beautyOption.setBrightLevel(beauty_bright_progress);
        }
        RCRTCBeautyEngine.getInstance().setBeautyOption(isOpenBeauty, beautyOption);  // true 是使用美颜，false 不使用美颜
    }

    /**
     * 重置
     */
    public void reset() {
        beauty_whiteness_progress = 0;
        beauty_smooth_progress = 0;
        beauty_ruddy_progress = 0;
        beauty_bright_progress = 0;
        RCRTCBeautyOption beautyOption = RCRTCBeautyEngine.getInstance().getCurrentBeautyOption();
        beautyOption.setWhitenessLevel(beauty_whiteness_progress);
        beautyOption.setSmoothLevel(beauty_smooth_progress);
        beautyOption.setRuddyLevel(beauty_ruddy_progress);
        beautyOption.setBrightLevel(beauty_bright_progress);
        RCRTCBeautyEngine.getInstance().setBeautyOption(isOpenBeauty, beautyOption);  // true 是使用美颜，false 不使用美颜
    }


    public void switchBeauty(boolean isOpen) {
        this.isOpenBeauty = isOpen;
        RCRTCBeautyOption beautyOption = RCRTCBeautyEngine.getInstance().getCurrentBeautyOption();
        RCRTCBeautyEngine.getInstance().setBeautyOption(isOpenBeauty, beautyOption);  // true 是使用美颜，false 不使用美颜
    }

    public int getCurrentProgress(int type) {
        this.currentType = type;
        if (type == OPTIONS_TYPE1) {
            return beauty_whiteness_progress;
        }
        if (type == OPTIONS_TYPE2) {
            return beauty_smooth_progress;
        }
        if (type == OPTIONS_TYPE3) {
            return beauty_ruddy_progress;
        }
        if (type == OPTIONS_TYPE4) {
            return beauty_bright_progress;
        }
        return 0;
    }


    /**
     * 更新滤镜模式
     * @param filterType
     */
    public void updateFilterMode(int filterType) {
        if (filterType == FILTER_TYPE_NONE) {
            //无滤镜模式
            RCRTCBeautyEngine.getInstance().setBeautyFilter(RCRTCBeautyFilter.NONE);
        }
        if (filterType == FILTER_TYPE1) {
            //唯美模式
            RCRTCBeautyEngine.getInstance().setBeautyFilter(RCRTCBeautyFilter.ESTHETIC);  // 唯美
        }
        if (filterType == FILTER_TYPE2) {
            //清新模式
            RCRTCBeautyEngine.getInstance().setBeautyFilter(RCRTCBeautyFilter.FRESH);  // 清新
        }
        if (filterType == FILTER_TYPE3) {
            //浪漫模式
            RCRTCBeautyEngine.getInstance().setBeautyFilter(RCRTCBeautyFilter.ROMANTIC);  // 浪漫
        }
    }
}
