package cd.casic.ci.process.util.snowflake;

import com.baomidou.mybatisplus.core.incrementer.IdentifierGenerator;
import org.springframework.stereotype.Component;

@Component
public class SnowflakeIdentifierGenerator implements IdentifierGenerator {
    private final SnowflakeIdWorker idWorker;

    public SnowflakeIdentifierGenerator() {
        this(1,1);
    }

    public SnowflakeIdentifierGenerator(long workerId, long datacenterId) {
        this.idWorker = new SnowflakeIdWorker(workerId, datacenterId);
    }

    @Override
    public Number nextId(Object entity) {
        return idWorker.nextId();
    }

    @Override
    public String nextUUID(Object entity) {
        return String.valueOf(idWorker.nextId());
    }
}
