package com.haha.common.enums;

import com.haha.common.vo.StatusLabel;
import lombok.Getter;

/**
 * 上货记录状态枚举
 */
@Getter
public enum StockRecordStatus {

    IN_PROGRESS(1, "进行中", "primary"),
    COMPLETED(2, "已完成", "success"),
    CANCELLED(3, "已取消", "danger");

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

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

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

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

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