package org.jeecg.modules.bytedance.advertise.enums;

import org.jeecg.common.util.DateUtils;

import java.util.HashMap;
import java.util.Map;
import java.util.TimeZone;

public enum BytedanceCreativeMatTypeEnum {
    /**
     * 创意素材类型
     * 0 表示当天
     */
    BYTEDANCE_CREATIVE_MAT_TYPE_ENUM_NEW("1","上新",0L,0L),
    BYTEDANCE_CREATIVE_MAT_TYPE_ENUM_HIGH_QUALITY("2","高质量",-4*60*24L,-1*60*24L),
    BYTEDANCE_CREATIVE_MAT_TYPE_ENUM_MISSING("3","遗漏",-8*60*24L,-1*60*24L),
    BYTEDANCE_CREATIVE_MAT_TYPE_ENUM_HISTORY("4","打捞",-8*60*24L,-1*60*24L),




    BYTEDANCE_CREATIVE_IMAGE_MODE_LARGE("CREATIVE_IMAGE_MODE_LARGE","1","大图横图"),
    BYTEDANCE_CREATIVE_IMAGE_MODE_LARGE_VERTICAL("CREATIVE_IMAGE_MODE_LARGE_VERTICAL","2","大图竖图"),
    BYTEDANCE_CREATIVE_IMAGE_MODE_UNION_SPLASH("CREATIVE_IMAGE_MODE_UNION_SPLASH","3","开屏"),
    BYTEDANCE_CREATIVE_IMAGE_MODE_VIDEO("CREATIVE_IMAGE_MODE_VIDEO","1","横版视频"),
    BYTEDANCE_CREATIVE_IMAGE_MODE_VIDEO_VERTICAL("CREATIVE_IMAGE_MODE_VIDEO_VERTICAL","2","竖版视频");





    /**
     * 类型
     */
    private String type;
    /**
     * 名称
     */
    private String name;
    /**
     * 素材查询的时间区间
     */
    private Long videoGetStartTime;
    private Long videoGetEndTime;

    private String imageMode;

    BytedanceCreativeMatTypeEnum(String type, String name,Long videoGetStartTime,Long videoGetEndTime) {
        this.type = type;
        this.name = name;
        this.videoGetStartTime = videoGetStartTime;
        this.videoGetEndTime = videoGetEndTime;
    }

    public static String getNameByType(String type) {
        for (BytedanceCreativeMatTypeEnum createTypeEnum : BytedanceCreativeMatTypeEnum.values()) {
            if (createTypeEnum.getType().equals(type)) {
                return createTypeEnum.getName();
            }
        }
        return "";
    }

    public static Long getStartTimeByType(String type) {
        for (BytedanceCreativeMatTypeEnum createTypeEnum : BytedanceCreativeMatTypeEnum.values()) {
            if (createTypeEnum.getType().equals(type)) {
                return createTypeEnum.getVideoGetStartTime();
            }
        }
        return -60*8L;
    }

    public static Long getEndTimeByType(String type) {
        for (BytedanceCreativeMatTypeEnum createTypeEnum : BytedanceCreativeMatTypeEnum.values()) {
            if (createTypeEnum.getType().equals(type)) {
                return createTypeEnum.getVideoGetEndTime();
            }
        }
        return -5L;
    }

    public String getType() {
        return this.type;
    }

    public String getName() {
        return this.name;
    }

    public void setType(String type) {
        this.type = type;
    }

    public void setName(String value) {
        this.name = value;
    }

    public Long getVideoGetStartTime() {
        return videoGetStartTime;
    }

    public void setVideoGetStartTime(Long videoGetStartTime) {
        this.videoGetStartTime = videoGetStartTime;
    }

    public Long getVideoGetEndTime() {
        return videoGetEndTime;
    }

    public void setVideoGetEndTime(Long videoGetEndTime) {
        this.videoGetEndTime = videoGetEndTime;
    }


    public String getImageMode() {
        return imageMode;
    }

    public void setImageMode(String imageMode) {
        this.imageMode = imageMode;
    }


    BytedanceCreativeMatTypeEnum(String type, String name,String imageMode) {
        this.type = type;
        this.name = name;
        this.imageMode = imageMode;
    }


    public static String getImageModeByType(String type) {
        for (BytedanceCreativeMatTypeEnum createTypeEnum : BytedanceCreativeMatTypeEnum.values()) {
            if (createTypeEnum.getType().equals(type)) {
                return createTypeEnum.getImageMode();
            }
        }
        return "";
    }




    /**
     *查询相应的素材信息  时间点
     * @param type 类型
     * 1-上新 当天
     * 2-高质量 前5天 花费大于500
     * 3-遗漏
     * 4-打捞 前7天
     * @return
     */
    public static Map<String,String> getCreativeStartTime(String type){
        Map<String,String> map = new HashMap();
        Long timeStart = BytedanceCreativeMatTypeEnum.getStartTimeByType(type);
        Long timeEnd = BytedanceCreativeMatTypeEnum.getEndTimeByType(type);
        Long now = System.currentTimeMillis();
        long zero = now / (1000*3600*24)*(1000*3600*24) - TimeZone.getDefault().getRawOffset();//今天零点零分零秒的毫秒数
        long twelve = zero + 24*60*60*1000 - 1;//今天23点59分59秒的毫秒数
        String startTime = DateUtils.formatDateTime(zero);
        String endTime = DateUtils.formatDateTime(twelve);
        if(timeStart != 0){
            startTime = DateUtils.formatDateTime(zero + timeStart * 60 * 1000L);
        }
        if(timeEnd != 0){
            endTime = DateUtils.formatDateTime(twelve + timeEnd * 60 * 1000L);
        }
        map.put("startTime",startTime);
        map.put("endTime",endTime);
        return map;
    }

}
