package com.crowdin.cli.properties;

import com.crowdin.cli.commands.Outputter;
import com.crowdin.cli.utils.file.FileUtils;

import java.io.File;
import java.util.Map;

import static com.crowdin.cli.properties.PropertiesBuilder.CONFIG_FILE_PATH;

public class PropertiesBuilders {

    public PropertiesWithFiles buildPropertiesWithFiles(Outputter out, File configFile, File identityFile, ParamsWithFiles params) {
        return new PropertiesWithFilesBuilder(out)
            .addConfigParams((fileExists(configFile) || params.isEmpty()) ? readConfigFile(configFile) : null)
            .addIdentityParams((identityFile != null) ? FileUtils.readYamlFile(identityFile) : null)
            .addParams(params)
            .build();
    }

    public PropertiesWithTargets buildPropertiesWithTargets(Outputter out, File configFile, File identityFile, ParamsWithTargets params) {
        return new PropertiesWithTargetsBuilder(out)
            .addConfigParams((configFile != null) ? readConfigFile(configFile) : null)
            .addIdentityParams((identityFile != null) ? FileUtils.readYamlFile(identityFile) : null)
            .addParams(params)
            .build();
    }

    public ProjectProperties buildProjectProperties(Outputter out, File configFile, File identityFile, ProjectParams params) {
        return new ProjectPropertiesBuilder(out)
            .addConfigParams((fileExists(configFile)) ? readConfigFile(configFile) : null)
            .addIdentityParams((identityFile != null) ? FileUtils.readYamlFile(identityFile) : null)
            .addParams(params)
            .build();
    }

    public BaseProperties buildBaseProperties(Outputter out, File configFile, File identityFile, BaseParams params) {
        return new BasePropertiesBuilder(out)
            .addConfigParams((fileExists(configFile)) ? readConfigFile(configFile) : null)
            .addIdentityParams((identityFile != null) ? FileUtils.readYamlFile(identityFile) : null)
            .addParams(params)
            .build();
    }

    public AllProperties buildChecker(Outputter out, File configFile, File identityFile, NoParams params) {
        return new PropertiesBuilderChecker(out)
            .addConfigParams((fileExists(configFile)) ? readConfigFile(configFile) : null)
            .addIdentityParams((identityFile != null) ? FileUtils.readYamlFile(identityFile) : null)
            .addParams(params)
            .build();
    }

    private Map<String, Object> readConfigFile(File configFile) {
        Map<String, Object> configFileParams = FileUtils.readYamlFile(configFile);
        configFileParams.put(CONFIG_FILE_PATH, configFile.getAbsoluteFile().getParentFile().getAbsolutePath());
        return configFileParams;
    }

    private boolean fileExists(File file) {
        return file != null && file.exists();
    }

    public NoProperties buildNoProperties() {
        return new NoProperties();
    }
}

@@ -117,16 +117,61 @@
 leUtils;
+%0Aimport org.apache.commons.lang3.StringUtils;
 %0A%0Aimport
@@ -598,32 +598,65 @@
 gFile(configFile
+, isParamsContainBasePath(params)
 ) : null)%0A      
@@ -1071,32 +1071,65 @@
 gFile(configFile
+, isParamsContainBasePath(params)
 ) : null)%0A      
@@ -1532,32 +1532,65 @@
 gFile(configFile
+, isParamsContainBasePath(params)
 ) : null)%0A      
@@ -1981,32 +1981,65 @@
 gFile(configFile
+, isParamsContainBasePath(params)
 ) : null)%0A      
@@ -2427,24 +2427,31 @@
 e(configFile
+, false
 ) : null)%0A  
@@ -2671,16 +2671,38 @@
 nfigFile
+, boolean skipFilePath
 ) %7B%0A    
@@ -2780,16 +2780,49 @@
 gFile);%0A
+        if (!skipFilePath) %7B%0A    
         
@@ -2925,16 +2925,26 @@
 ath());%0A
+        %7D%0A
         
@@ -2967,32 +2967,170 @@
 eParams;%0A    %7D%0A%0A
+    private boolean isParamsContainBasePath(BaseParams params) %7B%0A        return StringUtils.isNotEmpty(params.getBasePathParam());%0A    %7D%0A%0A
     private bool

Fix relative base paths for params