package com.ez.ertc.meeting.presenter;

import com.ez.ertc.meeting.bean.ErtcBeautyFilterEnum;
import com.ez.baselib.utils.LogUtil;
import com.ez.ertc.meeting.bean.FaceBeauty;
import com.ez.ertc.meeting.constant.MtSets;
import com.ez.ertc.meeting.contract.BeautyConfigContract;
import com.ez.ertc.meeting.utils.BeautyUtil;
import com.ez.ertc.meeting.utils.FaceBeautyFilterEnum;

public class BeautyConfigPresenter implements BeautyConfigContract.Presenter {

    private BeautyConfigContract.View mView;
    private FaceBeauty faceBeautyConfig;

    public BeautyConfigPresenter(BeautyConfigContract.View mView) {
        this.mView = mView;
        mView.setPresenter(this);
    }

    @Override
    public void start() {
        mView.updateBeautyKit(getFaceBeauty());
    }

    @Override
    public FaceBeauty getFaceBeauty() {
        if (faceBeautyConfig == null){
            faceBeautyConfig = BeautyUtil.getFaceBeauty();
        }
        return faceBeautyConfig;
    }

    @Override
    public void setColorIntensity(int percent) {
        float value = 1.0f * percent / 100;
        getFaceBeauty().whitenessIntensity = value;
        MtSets.setColorIntensityPercent(percent);
        mView.updateBeautyKit(getFaceBeauty());
    }

    @Override
    public void setRedIntensity(int percent) {
        float value = 1.0f * percent / 100;
        getFaceBeauty().ruddyIntensity = value;
        MtSets.setRedIntensityPercent(percent);
        mView.updateBeautyKit(getFaceBeauty());
    }

    @Override
    public void setBlurIntensity(int percent) {
        float value = 1.0f * percent / 100;
        getFaceBeauty().smoothnessIntensity = value;
        MtSets.setBlurIntensityPercent(percent);
        mView.updateBeautyKit(getFaceBeauty());
    }

    @Override
    public void resetIntensity() {
        setBlurIntensity(getDefaultBlurIntensityPercent());
        setColorIntensity(getDefaultColorIntensityPercent());
        setRedIntensity(getDefaultRedIntensityPercent());
    }

    @Override
    public void setSelectedBeautyType(int type) {
        MtSets.setSelectedBeautyType(type);
    }

    @Override
    public int getSelectedBeautyType() {
        return MtSets.getSelectedBeautyType();
    }

    @Override
    public int getCachedColorIntensityPercent() {
        LogUtil.e("EZRtcImpl", "getCachedColorIntensityPercent==="+MtSets.getColorIntensityPercent());
        return MtSets.getColorIntensityPercent();
    }

    @Override
    public int getCachedRedIntensityPercent() {
        LogUtil.e("EZRtcImpl","getCachedRedIntensityPercent==="+MtSets.getRedIntensityPercent());
        return MtSets.getRedIntensityPercent();
    }

    @Override
    public int getCachedBlurIntensityPercent() {
        LogUtil.e("EZRtcImpl","getCachedBlurIntensityPercent==="+MtSets.getBlurIntensityPercent());
        return MtSets.getBlurIntensityPercent();
    }

    @Override
    public int getDefaultColorIntensityPercent() {
        return 30;
    }

    @Override
    public int getDefaultRedIntensityPercent() {
        return 30;
    }

    @Override
    public int getDefaultBlurIntensityPercent() {
        return 70;
    }

    @Override
    public void setNoIntensity() {
        setColorIntensity(0);
        setRedIntensity(0);
        setBlurIntensity(0);
    }

    @Override
    public void setFilterIntensity(String filterName, int percent) {
        float value = (float) (1.0*percent/100);
        MtSets.setFilterName(filterName);
        MtSets.setFilterIntensityPercent(percent);
        ErtcBeautyFilterEnum[] filterTypes = ErtcBeautyFilterEnum.values();
        for(ErtcBeautyFilterEnum filterType : filterTypes) {
            if(filterType.getFilterName() == filterName) {
                mView.updateBeautyFilter(filterType, value);
                break;
            }
        }
    }

    @Override
    public String getCachedFilterName() {
        if (MtSets.getFilterName() == null){
            return FaceBeautyFilterEnum.BAILIANG_1;
        } else {
            return MtSets.getFilterName();
        }
    }

    @Override
    public int getCachedFilterPercent() {
        return MtSets.getFilterIntensityPercent();
    }


}
