package com.crowdin.cli.properties;

import lombok.Data;
import lombok.EqualsAndHashCode;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import static com.crowdin.cli.BaseCli.RESOURCE_BUNDLE;
import static com.crowdin.cli.properties.PropertiesBuilder.TARGETS;

@EqualsAndHashCode(callSuper = true)
@Data
public class PropertiesWithTargets extends ProjectProperties {

    static PropertiesWithTargetsConfigurator CONFIGURATOR = new PropertiesWithTargetsConfigurator();

    private List<TargetBean> targets;

    static class PropertiesWithTargetsConfigurator implements PropertiesConfigurator<PropertiesWithTargets> {

        private PropertiesWithTargetsConfigurator() {

        }

        @Override
        public void populateWithValues(PropertiesWithTargets props, Map<String, Object> map) {
            props.setTargets(PropertiesBuilder.getListOfMaps(map, TARGETS)
                .stream()
                .map(TargetBean.CONFIGURATOR::buildFromMap)
                .collect(Collectors.toList()));
        }

        @Override
        public void populateWithDefaultValues(PropertiesWithTargets props) {
            for (TargetBean tb : props.getTargets()) {
                TargetBean.CONFIGURATOR.populateWithDefaultValues(tb);
            }
        }

        @Override
        public PropertiesBuilder.Messages checkProperties(PropertiesWithTargets props, CheckType checkType) {
            PropertiesBuilder.Messages messages = new PropertiesBuilder.Messages();
            if (props.getTargets() == null || props.getTargets().isEmpty()) {
                messages.addError(RESOURCE_BUNDLE.getString("error.config.empty_or_missed_section_targets"));
            } else {
                for (TargetBean tb : props.getTargets())  {
                    messages.addAllErrors(TargetBean.CONFIGURATOR.checkProperties(tb));
                }
            }
            return messages;
        }
    }
}

@@ -1139,24 +1139,193 @@
 ts props) %7B%0A
+            if (props.getTargets() == null) %7B%0A                throw new RuntimeException(RESOURCE_BUNDLE.getString(%22error.configuration_file_not_exist%22));%0A            %7D%0A
             

make lint throw error with no config file