package be.iminds.ilabt.jfed.rspec.model.impl;

import be.iminds.ilabt.jfed.rspec.model.Lease;
import be.iminds.ilabt.jfed.util.RFC3339Util;

import java.text.ParseException;
import java.util.Date;

/**
 * User: twalcari
 * Date: 1/27/2015
 * Time: 11:51
 */
public class BasicLease implements Lease {

    private final String leaseId;
    private final String clientId;
    private final String validFromString;
    private final String validUntilString;
    private final Date validFromDate;
    private final Date validUntilDate;

    /** copy constructor */
    public BasicLease(Lease orig) {
        this.leaseId = orig.getLeaseId();
        this.clientId = orig.getClientId();
        this.validFromDate = orig.getValidFromDate();
        this.validUntilDate = orig.getValidUntilDate();
        this.validFromString = orig.getValidFromString();
        this.validUntilString = orig.getValidUntilString();
    }

    public BasicLease(String leaseId, String clientId, Date validFromDate, Date validUntilDate) {
        this(leaseId, clientId,
                validFromDate, validUntilDate,
                RFC3339Util.dateToRFC3339String(validFromDate, true, true, true),
                RFC3339Util.dateToRFC3339String(validUntilDate, true, true, true));
    }
    public BasicLease(String leaseId, String clientId, Date validFromDate, Date validUntilDate, String validFromString, String validUntilString) {
        this.leaseId = leaseId;
        this.clientId = clientId;
        this.validFromDate = validFromDate;
        this.validUntilDate = validUntilDate;
        this.validFromString = validFromString;
        this.validUntilString = validUntilString;
        try {
            assert RFC3339Util.rfc3339StringToDate(validFromString) != null;
            assert RFC3339Util.rfc3339StringToDate(validUntilString) != null;
        } catch (ParseException e) {
            assert false : "There was a parse exception ";
        }
    }

    public String getClientId() {
        return clientId;
    }

    public String getLeaseId() {
        return leaseId;
    }

    public Date getValidFromDate() {
        return validFromDate;
    }

    public Date getValidUntilDate() {
        return validUntilDate;
    }

    public String getValidFromString() {
        return validFromString;
    }

    public String getValidUntilString() {
        return validUntilString;
    }
}
