package com.snack.server.module.seckill.enums;

import lombok.Getter;

/**
 * 抢购活动状态
 */
@Getter
public enum SeckillActivityStatusEnum {

    NOT_STARTED(0, "未开始"),
    IN_PROGRESS(1, "进行中"),
    ENDED(2, "已结束");

    private final Integer code;
    private final String desc;

    SeckillActivityStatusEnum(Integer code, String desc) {
        this.code = code;
        this.desc = desc;
    }

    /**
     * 根据时间计算状态（用于显示态）
     */
    public static Integer calcStatus(java.time.LocalDateTime start, java.time.LocalDateTime end) {
        java.time.LocalDateTime now = java.time.LocalDateTime.now();
        if (now.isBefore(start)) return NOT_STARTED.getCode();
        if (now.isAfter(end))     return ENDED.getCode();
        return IN_PROGRESS.getCode();
    }
}
