package com.infoclinika.pdx.projection;

import com.infoclinika.pdx.domain.sample.SampleType;

import java.util.HashSet;
import java.util.Objects;
import java.util.Set;

/**
 * Statistics grouped by project.
 */
public class AggregateProjectStatistics {
    private Long projectId;
    private String projectName;
    private Set<SampleType> sampleTypes;
    private Set<IdAndNameDto> primarySites;
    private long casesAmount;
    private long expressionCasesAmount;
    private long mutationCasesAmount;

    public AggregateProjectStatistics() {
        sampleTypes = new HashSet<>();
        primarySites = new HashSet<>();
    }

    /**
     * All fields constructor.
     */
    public AggregateProjectStatistics(IdAndNameDto project, Set<SampleType> sampleTypes, Set<IdAndNameDto> primarySites,
                                      long casesAmount, long expressionCasesAmount, long mutationCasesAmount) {
        this.projectId = project.getId();
        this.projectName = project.getName();
        this.sampleTypes = sampleTypes;
        this.primarySites = primarySites;
        this.casesAmount = casesAmount;
        this.expressionCasesAmount = expressionCasesAmount;
        this.mutationCasesAmount = mutationCasesAmount;
    }

    public String getProjectName() {
        return projectName;
    }

    public void setProjectName(String projectName) {
        this.projectName = projectName;
    }

    public Long getProjectId() {
        return projectId;
    }

    public void setProjectId(Long projectId) {
        this.projectId = projectId;
    }

    public Set<SampleType> getSampleTypes() {
        return sampleTypes;
    }

    public void setSampleTypes(Set<SampleType> sampleTypes) {
        this.sampleTypes = sampleTypes;
    }

    public Set<IdAndNameDto> getPrimarySites() {
        return primarySites;
    }

    public void setPrimarySites(Set<IdAndNameDto> primarySites) {
        this.primarySites = primarySites;
    }

    public long getCasesAmount() {
        return casesAmount;
    }

    public void setCasesAmount(long casesAmount) {
        this.casesAmount = casesAmount;
    }

    public long getExpressionCasesAmount() {
        return expressionCasesAmount;
    }

    public void setExpressionCasesAmount(long expressionCasesAmount) {
        this.expressionCasesAmount = expressionCasesAmount;
    }

    public long getMutationCasesAmount() {
        return mutationCasesAmount;
    }

    public void setMutationCasesAmount(long mutationCasesAmount) {
        this.mutationCasesAmount = mutationCasesAmount;
    }

    public void addSampleType(SampleType sampleType) {
        this.sampleTypes.add(sampleType);
    }

    public void addPrimarySite(IdAndNameDto primarySite) {
        this.primarySites.add(primarySite);
    }

    public void incrementCases() {
        this.casesAmount++;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }
        final AggregateProjectStatistics that = (AggregateProjectStatistics) o;
        return getCasesAmount() == that.getCasesAmount()
               && getExpressionCasesAmount() == that.getExpressionCasesAmount()
               && getMutationCasesAmount() == that.getMutationCasesAmount()
               && Objects.equals(getProjectId(), that.getProjectId())
               && Objects.equals(getProjectName(), that.getProjectName())
               && Objects.equals(getSampleTypes(), that.getSampleTypes())
               && Objects.equals(getPrimarySites(), that.getPrimarySites());
    }

    @Override
    public int hashCode() {
        return Objects.hash(getProjectId(), getProjectName(), getSampleTypes(), getPrimarySites(),
                            getCasesAmount(), getExpressionCasesAmount(), getMutationCasesAmount());
    }

    @Override
    public String toString() {
        return "AggregateProjectStatistics{"
               + "projectId=" + projectId
               + ", projectName='" + projectName + '\''
               + ", sampleTypes=" + sampleTypes
               + ", primarySites=" + primarySites
               + ", casesAmount=" + casesAmount
               + ", expressionCasesAmount=" + expressionCasesAmount
               + ", mutationCasesAmount=" + mutationCasesAmount
               + '}';
    }
}
