package com.ez.ertc.meeting.utils;

import com.ez.ertc.meeting.R;
import com.ez.ertc.meeting.base.YsBaseDto;
import com.ez.ertc.meeting.bean.ErtcBeautyFilterEnum;
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.ui.BeautyConfigHolder;
import com.ez.ertc.meeting.ui.BeautyConfigHolder.*;

import java.util.ArrayList;
import java.util.List;


public class BeautyUtil {
    public static List<YsBaseDto> generateFilterDTO(final int defaultFilterPercent, int cachedPercent, final String cachedFilterName, final OnItemSelected filterListener){
        List<YsBaseDto> list = new ArrayList<YsBaseDto>(){{
            add(new BeautyDTO(R.string.ys_mt_beauty_config_beauty_none,R.drawable.ezm_ic_beauty_none,-1, BeautyType.NONE,false,filterListener));
            add(new FilterDTO(R.string.ys_mt_beauty_filter_ertc_1,R.drawable.icon_mt_beauty_filter_baixi,defaultFilterPercent, ErtcBeautyFilterEnum.FILTER_1.getFilterName(),false,filterListener));
            add(new FilterDTO(R.string.ys_mt_beauty_filter_ertc_2,R.drawable.icon_mt_beauty_filter_wennuan,defaultFilterPercent, ErtcBeautyFilterEnum.FILTER_2.getFilterName(),false,filterListener));
            add(new FilterDTO(R.string.ys_mt_beauty_filter_ertc_3,R.drawable.icon_mt_beauty_filter_qingchun,defaultFilterPercent, ErtcBeautyFilterEnum.FILTER_3.getFilterName(),false,filterListener));
            add(new FilterDTO(R.string.ys_mt_beauty_filter_ertc_4,R.drawable.icon_mt_beauty_filter_huahai,defaultFilterPercent, ErtcBeautyFilterEnum.FILTER_4.getFilterName(),false,filterListener));
            add(new FilterDTO(R.string.ys_mt_beauty_filter_ertc_5,R.drawable.icon_mt_beauty_filter_qingxin,defaultFilterPercent, ErtcBeautyFilterEnum.FILTER_5.getFilterName(),false,filterListener));
            add(new FilterDTO(R.string.ys_mt_beauty_filter_ertc_6,R.drawable.icon_mt_beauty_filter_tianmei,defaultFilterPercent, ErtcBeautyFilterEnum.FILTER_6.getFilterName(),false,filterListener));
            add(new FilterDTO(R.string.ys_mt_beauty_filter_ertc_7,R.drawable.icon_mt_beauty_filter_luokeke,defaultFilterPercent, ErtcBeautyFilterEnum.FILTER_7.getFilterName(),false,filterListener));
            add(new FilterDTO(R.string.ys_mt_beauty_filter_ertc_8,R.drawable.icon_mt_beauty_filter_shengxia,defaultFilterPercent, ErtcBeautyFilterEnum.FILTER_8.getFilterName(),false,filterListener));
            add(new FilterDTO(R.string.ys_mt_beauty_filter_ertc_9,R.drawable.icon_mt_beauty_filter_shaonv,defaultFilterPercent, ErtcBeautyFilterEnum.FILTER_9.getFilterName(),false,filterListener));
            add(new FilterDTO(R.string.ys_mt_beauty_filter_ertc_10,R.drawable.icon_mt_beauty_filter_mingkuai,defaultFilterPercent, ErtcBeautyFilterEnum.FILTER_10.getFilterName(),false,filterListener));
            add(new FilterDTO(R.string.ys_mt_beauty_filter_ertc_11,R.drawable.icon_mt_beauty_filter_fugu,defaultFilterPercent, ErtcBeautyFilterEnum.FILTER_11.getFilterName(),false,filterListener));
            add(new FilterDTO(R.string.ys_mt_beauty_filter_ertc_12,R.drawable.icon_mt_beauty_filter_tuise,defaultFilterPercent, ErtcBeautyFilterEnum.FILTER_12.getFilterName(),false,filterListener));
            }};
        boolean hasSelected = false;
        if (cachedFilterName == null || FaceBeautyFilterEnum.ORIGIN.equals(cachedFilterName)){
            ((BeautyDTO)list.get(0)).selected = true;
            hasSelected = true;
        } else {
            for (int i = 1; i < list.size(); i++) {
                FilterDTO filterDTO = (FilterDTO) list.get(i);
                if (filterDTO.filterName.equals(cachedFilterName)){
                    filterDTO.selected = true;
                    filterDTO.changedProgress = cachedPercent;
                    hasSelected = true;
                    break;
                }
            }
        }
        if (!hasSelected){
            ((BeautyDTO)list.get(0)).selected = true;
        }
        return list;
    }
    public static List<YsBaseDto> generateBeautyDTO(BeautyConfigContract.Presenter presenter,
                                                    final BeautyConfigHolder.OnItemSelected beautyListener){
        final int blurIntensityPercent = presenter.getCachedBlurIntensityPercent();
        final int colorIntensityPercent = presenter.getCachedColorIntensityPercent();
        final int redIntensityPercent = presenter.getCachedRedIntensityPercent();
        int selectedType = presenter.getSelectedBeautyType();
        List<YsBaseDto> list = new ArrayList<YsBaseDto>();
        BeautyDTO dto = new BeautyDTO(R.string.ys_mt_beauty_config_beauty_none,
                R.drawable.ezm_ic_beauty_none,
                -1,
                BeautyType.NONE,
                selectedType == BeautyType.NONE,
                beautyListener);
        list.add(dto);
        dto = new BeautyDTO(R.string.ys_mt_beauty_config_beauty_mopi,
                R.drawable.ezm_ic_beauty_mopi,
                presenter.getDefaultBlurIntensityPercent(),
                BeautyType.BLUR,
                selectedType == BeautyType.BLUR,
                beautyListener);
        dto.changedProgress = blurIntensityPercent;
        list.add(dto);
        dto = new BeautyDTO(R.string.ys_mt_beauty_config_beauty_meibai,
                R.drawable.ezm_ic_beauty_meibai,
                presenter.getDefaultColorIntensityPercent(),
                BeautyType.COLOR,
                selectedType == BeautyType.COLOR,
                beautyListener);
        dto.changedProgress = colorIntensityPercent;
        list.add(dto);
        dto = new BeautyDTO(R.string.ys_mt_beauty_config_beauty_hongrun,
                R.drawable.ezm_ic_beauty_hongrun,
                presenter.getDefaultRedIntensityPercent(),
                BeautyType.RED,
                selectedType == BeautyType.RED,
                beautyListener);
        dto.changedProgress = redIntensityPercent;
        list.add(dto);
        return list;
    }
    public static FaceBeauty getFaceBeauty(){
        String filterName = null;
        if (MtSets.getFilterName() == null){
            filterName = FaceBeautyFilterEnum.BAILIANG_1;
        } else {
            filterName = MtSets.getFilterName();
        }
        FaceBeauty faceBeautyConfig = new FaceBeauty();
//        faceBeautyConfig.setFilterName(filterName);//滤镜名称
//        faceBeautyConfig.setFilterIntensity(MtSets.getFilterIntensityPercent() * 0.01);//滤镜程度 范围[0.0-1.0]
//        faceBeautyConfig.setBlurType(FaceBeautyBlurTypeEnum.FineSkin);
//        faceBeautyConfig.setSharpenIntensity(0.2D);

        faceBeautyConfig.whitenessIntensity = MtSets.getColorIntensityPercent() * 0.01f;//美白 范围[0.0-1.0]
        faceBeautyConfig.ruddyIntensity = MtSets.getRedIntensityPercent() * 0.01f;//红润 范围[0.0-1.0]
        faceBeautyConfig.smoothnessIntensity = MtSets.getBlurIntensityPercent() * 0.01f;//磨皮 范围[0.0-1.0]

//        faceBeautyConfig.setFaceShapeIntensity(1.0D);
//        faceBeautyConfig.setEyeEnlargingIntensity(0.4D);
//        faceBeautyConfig.setCheekVIntensity(0.5D);
//        faceBeautyConfig.setNoseIntensity(0.5D);
//        faceBeautyConfig.setForHeadIntensity(0.3D);
//        faceBeautyConfig.setMouthIntensity(0.4D);
//        faceBeautyConfig.setChinIntensity(0.3D);
        return faceBeautyConfig;
    }
}
