package com.fs.system.config;

import cn.hutool.core.lang.Snowflake;
import cn.hutool.core.util.IdUtil;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;

public class SnowflakeUtils {

    private static Snowflake snowflake;

    public static void init(long workerId, long datacenterId){
        snowflake = IdUtil.getSnowflake(workerId, datacenterId);
    }

    public static String nextId() {
        if (snowflake == null) {
            throw new IllegalStateException("SnowflakeUtils not initialized");
        }
        return snowflake.nextIdStr();
    }

    public static long nextIdLong() {
        if (snowflake == null) {
            throw new IllegalStateException("SnowflakeUtils not initialized");
        }
        return snowflake.nextId();
    }
}
