package uk.gov.dvla.domain;

import com.google.code.morphia.annotations.Embedded;
import com.google.code.morphia.annotations.Property;
import uk.gov.dvla.domain.mib.TestPassStatus;

import java.util.Calendar;
import java.util.Date;
import java.util.List;

@Embedded
public class Entitlement {

    private String code;
    private Date validFrom;
    private Date validTo;
    private Date datePassed;

    @Property("provisional")
    private Boolean isProvisional = null;
    private Boolean isPriorTo = null;
    private Boolean isStated = null;
    private List<EntitlementRestriction> restrictions;

    // TODO - This should be removed when the TestPass class has been created
    @Property("unclaimedTestPass")
    private Integer unclaimedTestPassStatus = 0;

    public Date getDatePassed() {
        return datePassed;
    }

    public void setDatePassed(Date datePassed) {
        this.datePassed = datePassed;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public Date getValidFrom() {
        return validFrom;
    }

    public void setValidFrom(Date validFrom) {
        this.validFrom = validFrom;
    }

    public Date getValidTo() {
        return validTo;
    }

    public void setValidTo(Date validTo) {
        this.validTo = validTo;
    }

    public Boolean getIsProvisional() {
        return isProvisional;
    }

    public void setIsProvisional(Boolean provisional) {
        this.isProvisional = provisional;
    }

    public Boolean getIsPriorTo() {
        return isPriorTo;
    }

    public void setIsPriorTo(Boolean priorTo) {
        this.isPriorTo = priorTo;
    }

    public Boolean getIsStated() {
        return isStated;
    }

    public void setIsStated(Boolean isStated) {
        this.isStated = isStated;
    }

    public List<EntitlementRestriction> getRestrictions() {
        return restrictions;
    }

    public void setRestrictions(List<EntitlementRestriction> restrictions) {
        this.restrictions = restrictions;
    }

    public Integer getUnclaimedTestPassStatus() {
        return unclaimedTestPassStatus;
    }

    public void setUnclaimedTestPassStatus(Integer unclaimedTestPassStatus) {
        this.unclaimedTestPassStatus = unclaimedTestPassStatus;
    }

    public boolean isUnclaimedTestPass() {
        TestPassStatus testPassStatus = TestPassStatus.values()[getUnclaimedTestPassStatus()];

        return testPassStatus == TestPassStatus.Unclaimed;
    }

    public Date getUnclaimedTestPassExpiryDate() {

        Date expiryDate = null;

        if (getIsProvisional() && isUnclaimedTestPass()) {
            Integer unclaimedTestPassValidityInMonths = DomainConfiguration.getInstance().getUnclaimedTestPassValidity();

            Calendar c = Calendar.getInstance();
            c.setTime(getDatePassed());
            c.add(Calendar.MONTH, unclaimedTestPassValidityInMonths);

            expiryDate = c.getTime();
        }

        return expiryDate;
    }
}

@@ -128,16 +128,47 @@
 operty;%0A
+import org.joda.time.DateTime;%0A
 import u
@@ -210,35 +210,8 @@
 s;%0A%0A
-import java.util.Calendar;%0A
 impo
@@ -2792,17 +2792,16 @@
 dity();%0A
-%0A
         
@@ -2808,189 +2808,102 @@
     
-Calendar c = Calendar.getInstance();%0A            c.setTime(getDatePassed());%0A            c.add(Calendar.MONTH, unclaimedTestPassValidityInMonths);%0A%0A            expiryDate = c.getTim
+expiryDate = new DateTime(getDatePassed()).plusMonths(unclaimedTestPassValidityInMonths).toDat
 e();

Add tests for transform service