package com.qmth.boot.core.uid.config;

import com.qmth.boot.core.constant.CoreConstant;
import com.qmth.boot.core.uid.UidGenerator;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;

@Component
@ConfigurationProperties(prefix = CoreConstant.CONFIG_PREFIX + ".uid")
public class UidProperties {

    private int datacenterId = 0;

    @PostConstruct
    public void init() {
        if (datacenterId < 0 || datacenterId > UidGenerator.MAX_DATACENTER_ID) {
            throw new RuntimeException(
                    "[com.qmth.uid.datacenter-id] invalid, should between 0 and " + UidGenerator.MAX_DATACENTER_ID);
        }
    }

    public int getDatacenterId() {
        return datacenterId;
    }

    public void setDatacenterId(int datacenterId) {
        this.datacenterId = datacenterId;
    }

}
