package com.clx.performance.config;

import com.clx.performance.dao.AppDao;
import com.clx.performance.enums.AppEnum;
import com.clx.performance.enums.PerformanceResultEnum;
import com.clx.performance.model.App;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @Author liruixin
 * @create 2024-01-10 13:19
 */
@Component
public class LoadAppConfig {


    @Autowired
    private AppDao appDao;

    private App purchaseManageApp;

    private App smartWeightApp;


    public App getPurchaseManageApp() {
        if (purchaseManageApp == null) {
            purchaseManageApp = appDao.getOneByField(App::getUniqueIdentifier, AppEnum.UniqueIdentifier.PURCHASE_MANAGE.getCode()).orElseThrow(
                    PerformanceResultEnum.DATA_NOT_FIND);;
        }
        return purchaseManageApp;
    }

    public App getSmartWeightApp() {
        if (smartWeightApp == null) {
            smartWeightApp = appDao.getOneByField(App::getUniqueIdentifier, AppEnum.UniqueIdentifier.SMART_WEIGHT.getCode()).orElseThrow(
                    PerformanceResultEnum.DATA_NOT_FIND);
        }
        return smartWeightApp;
    }

}
