package org.cruk.mga.export;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlElementWrapper;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType;

import org.cruk.mga.MGAConfig;
import org.cruk.util.OrderedProperties;


@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(propOrder = { "runId", "properties", "trimStart", "trimLength", "summaries", "referenceGenomes" })
@XmlRootElement(name = "MultiGenomeAlignmentSummaries")
public class AllMGASummaries implements Serializable
{
    private static final long serialVersionUID = -3897311196228179946L;

    @XmlElement(name = "RunId", required = true)
    private String runId;

    @XmlElement(name = "Properties")
    private Properties properties;

    @XmlElement(name = "TrimStart")
    private Integer trimStart;

    @XmlElement(name = "TrimLength")
    private Integer trimLength;

    @XmlElement(name = "MultiGenomeAlignmentSummary")
    private List<MGASummary> summaries;

    @XmlElementWrapper(name = "ReferenceGenomes")
    @XmlElement(name = "ReferenceGenome")
    private List<ReferenceGenome> referenceGenomes;

    public AllMGASummaries()
    {
    }

    public AllMGASummaries(MGAConfig config)
    {
        runId = config.getRunId();
        trimStart = config.getTrimStart() == null ? null : config.getTrimStart().intValue();
        trimLength = config.getTrimLength() == null ? null : config.getTrimLength().intValue();
    }

    public AllMGASummaries(MGAConfig config, OrderedProperties runProperties)
    {
        this(config);

        properties = new Properties(runProperties);
    }

    public String getRunId()
    {
        return runId;
    }

    public void setRunId(String runId)
    {
        this.runId = runId;
    }

    public Integer getTrimStart()
    {
        return trimStart;
    }

    public void setTrimStart(Integer trimStart)
    {
        this.trimStart = trimStart;
    }

    public Integer getTrimLength()
    {
        return trimLength;
    }

    public void setTrimLength(Integer trimLength)
    {
        this.trimLength = trimLength;
    }

    public Properties getProperties()
    {
        return properties;
    }

    public void setProperties(OrderedProperties runProperties)
    {
        properties = null;
        if (runProperties != null)
        {
            properties = new Properties(runProperties);
        }
    }

    public List<MGASummary> getMultiGenomeAlignmentSummaries()
    {
        if (summaries == null)
        {
            summaries = new ArrayList<>();
        }
        return summaries;
    }

    public List<ReferenceGenome> getReferenceGenomes()
    {
        if (referenceGenomes == null)
        {
            referenceGenomes = new ArrayList<>();
        }
        return referenceGenomes;
    }

}

@@ -987,31 +987,27 @@
     private 
-I
+i
 nt
-eger
  trimStart;%0A
@@ -1056,23 +1056,19 @@
 private 
-I
+i
 nt
-eger
  trimLen
@@ -1485,36 +1485,33 @@
 art() == null ? 
-null
+0
  : config.getTri
@@ -1585,20 +1585,17 @@
  null ? 
-null
+0
  : confi
@@ -1944,39 +1944,35 @@
   %7D%0A%0A    public 
-I
+i
 nt
-eger
  getTrimStart()%0A
@@ -2039,23 +2039,19 @@
 imStart(
-I
+i
 nt
-eger
  trimSta
@@ -2114,23 +2114,19 @@
  public 
-I
+i
 nt
-eger
  getTrim
@@ -2208,15 +2208,11 @@
 gth(
-I
+i
 nt
-eger
  tri

Fix issue with trim start and length being written to the XML file as floating point numbers when they should be integers.