package org.jboss.da.reports.model.api;

import java.util.Collections;
import java.util.List;
import java.util.Objects;

import lombok.Getter;
import lombok.NonNull;
import lombok.ToString;

import org.jboss.da.model.rest.validators.ScmUrl;

/**
 *
 * @author Honza Brázdil <janinko.g@gmail.com>
 */
@ToString
public class SCMLocator {

    @Getter
    @NonNull
    @ScmUrl
    private String scmUrl;

    @Getter
    @NonNull
    private String revision;

    @Getter
    @NonNull
    private String pomPath;

    private Boolean internal;

    @Getter
    @NonNull
    private List<String> repositories;

    private SCMLocator(String scmUrl, String revision, String pomPath, List<String> repositories) {
        this.scmUrl = Objects.requireNonNull(scmUrl);
        this.revision = Objects.requireNonNull(revision);
        this.pomPath = Objects.requireNonNull(pomPath);
        this.repositories = Objects.requireNonNull(repositories);
    }

    public static SCMLocator internal(String scmUrl, String revision, String pomPath) {
        return internal(scmUrl, revision, pomPath, Collections.emptyList());
    }

    public static SCMLocator internal(String scmUrl, String revision, String pomPath,
            List<String> repositories) {
        SCMLocator ret = new SCMLocator(scmUrl, revision, pomPath, repositories);
        ret.internal = true;
        return ret;
    }

    public static SCMLocator external(String scmUrl, String revision, String pomPath) {
        return external(scmUrl, revision, pomPath, Collections.emptyList());
    }

    public static SCMLocator external(String scmUrl, String revision, String pomPath,
            List<String> repositories) {
        SCMLocator ret = new SCMLocator(scmUrl, revision, pomPath, repositories);
        ret.internal = false;
        return ret;
    }

    public static SCMLocator generic(String scmUrl, String revision, String pomPath) {
        return generic(scmUrl, revision, pomPath, Collections.emptyList());
    }

    public static SCMLocator generic(String scmUrl, String revision, String pomPath,
            List<String> repositories) {
        SCMLocator ret = new SCMLocator(scmUrl, revision, pomPath, repositories);
        ret.internal = null;
        return ret;
    }

    public boolean isInternal() {
        return internal != null && internal;
    }

    public boolean isExternal() {
        return internal != null && !internal;
    }
}

@@ -880,51 +880,142 @@
     
-this.repositories = Objects.requireNonNull(
+if (repositories == null) %7B%0A            this.repositories = Collections.emptyList();%0A        %7D else %7B%0A            this.repositories = 
 repo
@@ -1018,27 +1018,36 @@
 repositories
-)
 ;%0A
+        %7D%0A
     %7D%0A%0A    p
@@ -1180,39 +1180,20 @@
 omPath, 
-Collections.emptyList()
+null
 );%0A    %7D
@@ -1598,39 +1598,20 @@
 omPath, 
-Collections.emptyList()
+null
 );%0A    %7D

fix NPE in SCMLocator constructor