package com.fs.oms.config;

import lombok.Getter;
import lombok.Setter;
import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;

@Setter
@Getter
@Configuration
@ConfigurationProperties(prefix = "deliver")
public class DeliverConfig {
    private Map<String, DeliverCompanyConfig> companies = new HashMap<>();

    /**
     * 获取omsCode
     * @param erpCode ERP代码
     * @param isPri 私域还是公域
     * @return omsCode
     */
    public String getOmsCode(String erpCode, boolean isPri) {
        DeliverCompanyConfig companyConfig = companies.get(erpCode);
        if (companyConfig == null) {
            return null;
        }

        DeliverModeConfig modeConfig = isPri ? companyConfig.getPri() : companyConfig.getPub();
        return modeConfig != null ? modeConfig.getOmsCode() : null;
    }
}
