// Path: src/main/java/org/netmelody/cieye/core/domain/RunningBuild.java
// public final class RunningBuild {
//     
//     private final Percentage progress;
//     private final Status status;
// 
//     public RunningBuild() {
//         this(percentageOf(100), Status.GREEN);
//     }
// 
//     public RunningBuild(Percentage progress, Status status) {
//         this.progress = progress;
//         this.status = status;
//     }
//     
//     public static RunningBuild buildAt(Percentage progress) {
//         return buildAt(progress, Status.UNKNOWN);
//     }
//     
//     public static RunningBuild buildAt(Percentage progress, Status status) {
//         return new RunningBuild(progress, status);
//     }
//     
//     public Percentage progress() {
//         return progress;
//     }
//     
//     public Status status() {
//         return status;
//     }
// 
//     public RunningBuild advancedBy(int percentageIncrement) {
//         return new RunningBuild(percentageOf(Math.min(progress.value() + percentageIncrement, 100)), status);
//     }
// 
//     public RunningBuild withStatus(Status status) {
//         return new RunningBuild(progress, status);
//     }
// }
// 
// Path: src/main/java/org/netmelody/cieye/spies/teamcity/jsondomain/BuildDetail.java
// public final class BuildDetail {
//     public long id;
//     public String number;
//     public String status;
//     public String href;
//     public String webUrl;
//     public boolean personal;
//     public boolean history;
//     public boolean pinned;
//     public String statusText;
//     //buildType
//     public Date startDate;
//     public Date finishDate;
//     //agent
//     public Comment comment;
//     //tags
//     //properties
//     //revisions
//     public ChangesHref changes;
//     //relatedIssues
//     
//     public Status status() {
//         if (status == null || "SUCCESS".equals(status)) {
//             return Status.GREEN;
//         }
//         if (comment != null && comment.text != null && !comment.text.isEmpty()) {
//             return Status.UNDER_INVESTIGATION;
//         }
//         return Status.BROKEN;
//     }
// 
//     public long startDateTime() {
//         return (null == startDate) ? 0L : startDate.getTime();
//     }
// }
// 
// Path: src/main/java/org/netmelody/cieye/spies/teamcity/jsondomain/Investigation.java
// public final class Investigation {
//     public String id;
//     public String state;
//     public User responsible;
//     public Assignment assignment;
//     // scope;
//     
//     public long startDateTime() {
//         if (null == assignment) {
//             return 0L;
//         }
//         return (null == assignment.timestamp) ? 0L : assignment.timestamp.getTime();
//     }
// 
//     public boolean underInvestigation() {
//         return "TAKEN".equals(state) || "FIXED".equals(state);
//     }
// }


import static org.netmelody.cieye.core.domain.Percentage.percentageOf;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import org.netmelody.cieye.core.domain.RunningBuild;
import org.netmelody.cieye.core.domain.Sponsor;
import org.netmelody.cieye.core.domain.Status;
import org.netmelody.cieye.core.domain.TargetDetail;
import org.netmelody.cieye.core.observation.KnownOffendersDirectory;
import org.netmelody.cieye.spies.teamcity.jsondomain.Build;
import org.netmelody.cieye.spies.teamcity.jsondomain.BuildDetail;
import org.netmelody.cieye.spies.teamcity.jsondomain.BuildType;
import org.netmelody.cieye.spies.teamcity.jsondomain.BuildTypeDetail;
import org.netmelody.cieye.spies.teamcity.jsondomain.Change;
import org.netmelody.cieye.spies.teamcity.jsondomain.ChangeDetail;
import org.netmelody.cieye.spies.teamcity.jsondomain.Investigation;
package org.netmelody.cieye.spies.teamcity;




public final class BuildTypeAnalyser {

    private final TeamCityCommunicator communicator;
    private final KnownOffendersDirectory detective;

    public BuildTypeAnalyser(TeamCityCommunicator communicator, KnownOffendersDirectory detective) {
        this.communicator = communicator;
        this.detective = detective;
    }
    
    public TargetDetail targetFrom(BuildType buildType) {
        final BuildTypeDetail buildTypeDetail = communicator.detailsFor(buildType);
        
        if (buildTypeDetail.paused) {
            return new TargetDetail(communicator.endpoint() + buildType.href, buildType.webUrl(), buildType.name, Status.DISABLED, 0L);
        }
        
        final Set<Sponsor> sponsors = new HashSet<Sponsor>();
// Path: src/main/java/org/netmelody/cieye/core/domain/RunningBuild.java
// public final class RunningBuild {
//     
//     private final Percentage progress;
//     private final Status status;
// 
//     public RunningBuild() {
//         this(percentageOf(100), Status.GREEN);
//     }
// 
//     public RunningBuild(Percentage progress, Status status) {
//         this.progress = progress;
//         this.status = status;
//     }
//     
//     public static RunningBuild buildAt(Percentage progress) {
//         return buildAt(progress, Status.UNKNOWN);
//     }
//     
//     public static RunningBuild buildAt(Percentage progress, Status status) {
//         return new RunningBuild(progress, status);
//     }
//     
//     public Percentage progress() {
//         return progress;
//     }
//     
//     public Status status() {
//         return status;
//     }
// 
//     public RunningBuild advancedBy(int percentageIncrement) {
//         return new RunningBuild(percentageOf(Math.min(progress.value() + percentageIncrement, 100)), status);
//     }
// 
//     public RunningBuild withStatus(Status status) {
//         return new RunningBuild(progress, status);
//     }
// }
// 
// Path: src/main/java/org/netmelody/cieye/spies/teamcity/jsondomain/BuildDetail.java
// public final class BuildDetail {
//     public long id;
//     public String number;
//     public String status;
//     public String href;
//     public String webUrl;
//     public boolean personal;
//     public boolean history;
//     public boolean pinned;
//     public String statusText;
//     //buildType
//     public Date startDate;
//     public Date finishDate;
//     //agent
//     public Comment comment;
//     //tags
//     //properties
//     //revisions
//     public ChangesHref changes;
//     //relatedIssues
//     
//     public Status status() {
//         if (status == null || "SUCCESS".equals(status)) {
//             return Status.GREEN;
//         }
//         if (comment != null && comment.text != null && !comment.text.isEmpty()) {
//             return Status.UNDER_INVESTIGATION;
//         }
//         return Status.BROKEN;
//     }
// 
//     public long startDateTime() {
//         return (null == startDate) ? 0L : startDate.getTime();
//     }
// }
// 
// Path: src/main/java/org/netmelody/cieye/spies/teamcity/jsondomain/Investigation.java
// public final class Investigation {
//     public String id;
//     public String state;
//     public User responsible;
//     public Assignment assignment;
//     // scope;
//     
//     public long startDateTime() {
//         if (null == assignment) {
//             return 0L;
//         }
//         return (null == assignment.timestamp) ? 0L : assignment.timestamp.getTime();
//     }
// 
//     public boolean underInvestigation() {
//         return "TAKEN".equals(state) || "FIXED".equals(state);
//     }
// }


// Path: src/main/java/org/netmelody/cieye/spies/teamcity/BuildTypeAnalyser.java
import static org.netmelody.cieye.core.domain.Percentage.percentageOf;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import org.netmelody.cieye.core.domain.RunningBuild;
import org.netmelody.cieye.core.domain.Sponsor;
import org.netmelody.cieye.core.domain.Status;
import org.netmelody.cieye.core.domain.TargetDetail;
import org.netmelody.cieye.core.observation.KnownOffendersDirectory;
import org.netmelody.cieye.spies.teamcity.jsondomain.Build;
import org.netmelody.cieye.spies.teamcity.jsondomain.BuildDetail;
import org.netmelody.cieye.spies.teamcity.jsondomain.BuildType;
import org.netmelody.cieye.spies.teamcity.jsondomain.BuildTypeDetail;
import org.netmelody.cieye.spies.teamcity.jsondomain.Change;
import org.netmelody.cieye.spies.teamcity.jsondomain.ChangeDetail;
import org.netmelody.cieye.spies.teamcity.jsondomain.Investigation;

package org.netmelody.cieye.spies.teamcity;




public final class BuildTypeAnalyser {

    private final TeamCityCommunicator communicator;
    private final KnownOffendersDirectory detective;

    public BuildTypeAnalyser(TeamCityCommunicator communicator, KnownOffendersDirectory detective) {
        this.communicator = communicator;
        this.detective = detective;
    }
    
    public TargetDetail targetFrom(BuildType buildType) {
        final BuildTypeDetail buildTypeDetail = communicator.detailsFor(buildType);
        
        if (buildTypeDetail.paused) {
            return new TargetDetail(communicator.endpoint() + buildType.href, buildType.webUrl(), buildType.name, Status.DISABLED, 0L);
        }
        
        final Set<Sponsor> sponsors = new HashSet<Sponsor>();
        final List<RunningBuild> runningBuilds = new ArrayList<RunningBuild>();