package com.cyksj.model.entity;

import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
import lombok.Getter;
import lombok.experimental.Accessors;
import org.apache.commons.lang3.StringUtils;

import java.io.Serializable;
import java.util.stream.Stream;

@TableName(value ="order_don_post")
@Data
@Accessors(chain = true)
public class OrderDonPost extends BaseEntity implements Serializable {

    /**
     * 
     */
    private Long orderId;

    /**
     * 回传参数
     */
    private String callback;

    /**
     * 状态 true 已回传 false 未回传
     */
    private Boolean status;

    /**
     * Ks 快手 Dy抖音
     */
    private Type type;

    /**
     * 回传类型
     */
    private String evenType;


    @TableField(exist = false)
    private static final long serialVersionUID = 1L;

    /**
     * 回传渠道类型
     */
    @Getter
    public enum Type {

        /**
         * 抖音
         */
        DY("抖音回传", "Dy", "2"),

        /**
         * 微信
         */
        WeChat("微信回传", "WeChat", "PURCHASE"),

        /**
         * adq
         */
        adq("腾讯回传", "adq", "PURCHASE"),

        /**
         * 360点睛
         */
        DJ("360点睛", "dj","ORDER"),

        /**
         * 百度
         */
        BaiDu("百度回传", "BaiDu", "3"),

        /**
         * oceanengine回传
         */
        OE("巨量回传","OE","active_pay"),

        ;

        /**
         * 描述
         */
        private String desc;

        /**
         * 回传类型
         */
        private String type;

        /**
         * 类型 表单提交
         */
        private String evenType;


        Type(String desc, String type, String evenType) {
            this.desc = desc;
            this.type = type;
            this.evenType = evenType;
        }

        /**
         * 根据type 获取
         *
         * @param type
         * @return
         */
        @SuppressWarnings("rawtypes")
        public static Type getByType(String type) {
            return Stream.of(Type.values())
                    .filter((enums) -> enums.getType().equals(type)).findFirst().get();

        }

        /**
         * 根据type
         *
         * @param type
         * @return
         */
        @SuppressWarnings("rawtypes")
        public static Boolean verify(String type) {
            if (StringUtils.isBlank(type)) {
                return Boolean.FALSE;
            }
            return Stream.of(Type.values())
                    .anyMatch((enums) -> enums.getType().equals(type));
        }


    }
}