package com.qmth.boot.core.uid.service.impl;

import com.qmth.boot.core.uid.UidGenerator;
import com.qmth.boot.core.uid.config.UidProperties;
import com.qmth.boot.core.uid.service.UidMachineService;
import com.qmth.boot.core.uid.service.UidService;
import org.springframework.stereotype.Component;

@Component
public class LocalUidService implements UidService {

    private UidGenerator generator;

    public LocalUidService(UidMachineService uidMachineService, UidProperties uidProperties) {
        this.generator = new UidGenerator(uidProperties.getDatacenterId(), uidMachineService.getMachineId());
    }

    @Override
    public long getId() {
        return generator.next();
    }

}
