package dp.kotul.bamboospecsapplication.creator;

import com.atlassian.bamboo.specs.api.builders.plan.artifact.Artifact;
import dp.kotul.bamboospecsapplication.configuration.ArtifactConfiguration;
import java.util.ArrayList;
import java.util.List;

public class BuildArtifactCreator {
    private BuildArtifactCreator(){}

    public static Artifact[] createArtifacts(List<ArtifactConfiguration> artifactsFromConfig) {
        List<Artifact> artifacts = new ArrayList<>();
        for (ArtifactConfiguration artifactFromConfig : artifactsFromConfig) {
            Artifact artifact = new Artifact(artifactFromConfig.getName())
                    .copyPattern(artifactFromConfig.getCopyPattern())
                    .shared(artifactFromConfig.isShared())
                    .required(artifactFromConfig.isRequired());

            if (artifactFromConfig.getLocation() != null) {
                artifact.location(artifactFromConfig.getLocation());
            }

            artifacts.add(artifact);
        }
        return artifacts.stream().toArray(Artifact[]::new);
    }
}
