package com.github.blindpirate.gogradle.vcs.git;

import com.github.blindpirate.gogradle.core.dependency.AbstractResolvedDependency;
import com.github.blindpirate.gogradle.core.dependency.NotationDependency;
import com.google.common.collect.ImmutableMap;

import java.util.Map;

import static com.github.blindpirate.gogradle.core.dependency.parse.MapNotationParser.NAME_KEY;
import static com.github.blindpirate.gogradle.core.dependency.parse.MapNotationParser.VCS_KEY;
import static com.github.blindpirate.gogradle.vcs.VcsType.Git;
import static com.github.blindpirate.gogradle.vcs.git.GitNotationDependency.COMMIT_KEY;
import static com.github.blindpirate.gogradle.vcs.git.GitNotationDependency.URL_KEY;

public class GitResolvedDependency extends AbstractResolvedDependency {
    private String repoUrl;

    private GitResolvedDependency(String name, String commitId, long commitTime) {
        super(name, commitId, commitTime);
    }

    @Override
    public Map<String, Object> toLockedNotation() {
        return ImmutableMap.of(
                NAME_KEY, getName(),
                VCS_KEY, Git.getName(),
                URL_KEY, repoUrl,
                COMMIT_KEY, getVersion());
    }

    public static GitResolvedDependencyBuilder builder() {
        return new GitResolvedDependencyBuilder();
    }


    public static final class GitResolvedDependencyBuilder {
        private NotationDependency notationDependency;
        private String repoUrl;
        private String commitId;
        private long commitTime;
        private String name;

        private GitResolvedDependencyBuilder() {
        }


        public GitResolvedDependencyBuilder withRepoUrl(String repoUrl) {
            this.repoUrl = repoUrl;
            return this;
        }

        public GitResolvedDependencyBuilder withNotationDependency(NotationDependency notationDependency) {
            this.notationDependency = notationDependency;
            return this;
        }

        public GitResolvedDependencyBuilder withCommitId(String commitId) {
            this.commitId = commitId;
            return this;
        }

        public GitResolvedDependencyBuilder withCommitTime(long commitTime) {
            this.commitTime = commitTime;
            return this;
        }

        public GitResolvedDependencyBuilder withName(String name) {
            this.name = name;
            return this;
        }

        public GitResolvedDependency build() {
            GitResolvedDependency gitResolvedDependency = new GitResolvedDependency(name, commitId, commitTime);
            gitResolvedDependency.repoUrl = this.repoUrl;
            gitResolvedDependency.transitiveDepExclusions = notationDependency.getTransitiveDepExclusions();
            return gitResolvedDependency;
        }
    }
}

@@ -2485,37 +2485,19 @@
 endency 
-gitResolvedDependency
+ret
  = new G
@@ -2558,37 +2558,19 @@
         
-gitResolvedDependency
+ret
 .repoUrl
@@ -2598,37 +2598,85 @@
         
-gitResolvedDependency
+ret.setFirstLevel(notationDependency.isFirstLevel());%0A            ret
 .transit
@@ -2766,29 +2766,11 @@
 urn 
-gitResolvedDependency
+ret
 ;%0A  

set necessary fields when resolving dependency