package com.base.orbit.Exception;

import com.google.common.collect.Lists;

/**
 * 服务模块信息, 规则: 服务(3位) + 模块(3位)
 *
 * @author jhzhu
 * @date 2022-02-12
 */
public abstract class ServiceModuleInfo {


    // =========================基础数据服务[Start]=========================
    public static final Service SERVICE_ORBIT_BASE_SERVER = Service.builder()
            .code("100")
            .name("基础数据服务")
            .modules(Lists.newArrayList(
                    ServiceModuleInfo.SERVICE_ORBIT_BASE_SERVER_MODULE_USER
            ))
            .build();

    public static final Service.Module SERVICE_ORBIT_BASE_SERVER_MODULE_USER = Service.Module.builder()
            .service(ServiceModuleInfo.SERVICE_ORBIT_BASE_SERVER)
            .code("000")
            .name("用户模块")
            .build();

    public static final Service.Module SERVICE_ORBIT_BASE_SERVER_MODULE_TRACK = Service.Module.builder()
            .service(ServiceModuleInfo.SERVICE_ORBIT_BASE_SERVER)
            .code("001")
            .name("轨道计算模块")
            .build();

    public static final Service.Module SERVICE_ORBIT_BASE_SERVER_MODULE_STRIP = Service.Module.builder()
            .service(ServiceModuleInfo.SERVICE_ORBIT_BASE_SERVER)
            .code("002")
            .name("访问计算模块")
            .build();

    public static final Service.Module SERVICE_ORBIT_BASE_SERVER_MODULE_EVENTBUS = Service.Module.builder()
            .service(ServiceModuleInfo.SERVICE_ORBIT_BASE_SERVER)
            .code("003")
            .name("事件总线模块")
            .build();

    public static final Service.Module SERVICE_ORBIT_BASE_SERVER_MODULE_COMMON = Service.Module.builder()
            .service(ServiceModuleInfo.SERVICE_ORBIT_BASE_SERVER)
            .code("004")
            .name("通用模块")
            .build();


    public static class Builder {

        private Service service;
        private Service.Module module;
        private String serialNumber;

        public Builder service(Service service) {
            this.service = service;
            return this;
        }

        public Builder module(Service.Module module) {
            this.module = module;
            return this;
        }

        public Builder serialNumber(String serialNumber) {
            this.serialNumber = serialNumber;
            return this;
        }

        /**
         * 构建错误码, 规则: 服务(3位) + 模块(3位) + 序号(3位).
         *
         * @return 整型错误码
         */
        public String buildErrorCode() {
            return String.format("%s.%s.%s", service.getCode(), module.getCode(), serialNumber);
        }
    }

    public static Builder builder() {
        return new Builder();
    }
}
