package com.fs.event;

import lombok.AllArgsConstructor;
import lombok.Getter;
import org.springframework.context.ApplicationEvent;

import java.util.Arrays;

@Getter
public class ActiveClickEvent extends ApplicationEvent {

    private final Long activeId;
    private final Long userId;
    private final Type type;
    private final ProductType productType;
    private final Long resourceId;

    public ActiveClickEvent(Object source, Long activeId, Long userId, Type type) {
        super(source);
        this.activeId = activeId;
        this.userId = userId;
        this.type = type;
        this.productType = null;
        this.resourceId = null;
    }

    public ActiveClickEvent(Object source, Long activeId, Long userId, Type type, ProductType productType, Long resourceId) {
        super(source);
        this.activeId = activeId;
        this.userId = userId;
        this.type = type;
        this.productType = productType;
        this.resourceId = resourceId;
    }

    @Getter
    @AllArgsConstructor
    public enum Type {
        HOME(1), VIDEO(2), DOCTOR(3), PRODUCT(4);
        private final Integer value;
        public static Type valueOf(Integer value) {
            if (value == null)
                return null;
            return Arrays.stream(Type.values()).filter(t -> t.value.equals(value)).findFirst().orElse(null);
        }
    }

    @Getter
    @AllArgsConstructor
    public enum ProductType {
        PACKAGE(1), INTEGRAL(2);
        private final Integer value;
        public static ProductType valueOf(Integer value) {
            if (value == null)
                return null;
            return Arrays.stream(ProductType.values()).filter(productType -> productType.value.equals(value)).findFirst().orElse(null);
        }
    }

}
