package com.haha.common.enums;

import com.haha.common.vo.StatusLabel;

public enum ActivityStatusEnum {

    DRAFT(0, "草稿", "info"),
    PUBLISHED(1, "已发布", "primary"),
    ONGOING(2, "进行中", "success"),
    PAUSED(3, "已暂停", "warning"),
    ENDED(4, "已结束", "danger");

    private final int code;
    private final String label;
    private final String color;

    ActivityStatusEnum(int code, String label, String color) {
        this.code = code;
        this.label = label;
        this.color = color;
    }

    public int getCode() {
        return code;
    }

    public String getLabel() {
        return label;
    }

    public String getColor() {
        return color;
    }

    public StatusLabel getStatusLabel() {
        return new StatusLabel(label, color);
    }

    public static StatusLabel getLabelByCode(Integer code) {
        if (code == null) {
            return StatusLabel.info("未知");
        }
        for (ActivityStatusEnum status : values()) {
            if (status.code == code) {
                return status.getStatusLabel();
            }
        }
        return StatusLabel.info("未知");
    }

    public static ActivityStatusEnum getByCode(Integer code) {
        if (code == null) {
            return null;
        }
        for (ActivityStatusEnum status : values()) {
            if (status.code == code) {
                return status;
            }
        }
        return null;
    }

    public static boolean canEdit(Integer status) {
        return status != null && status == DRAFT.code;
    }

    public static boolean canPublish(Integer status) {
        return status != null && status == DRAFT.code;
    }

    public static boolean canPause(Integer status) {
        return status != null && status == ONGOING.code;
    }

    public static boolean canResume(Integer status) {
        return status != null && status == PAUSED.code;
    }

    public static boolean canDelete(Integer status) {
        return status != null && (status == DRAFT.code || status == ENDED.code);
    }
}
