package com.jscape.inspect;

import com.jscape.inet.dns.DnsResponse;

import java.io.Serializable;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;

/**
 * Represents cached DNS response.
 */
public class DnsResponseCached
        implements Serializable {

    /**
     * Response.
     */
    protected DnsResponse response;
    /**
     * Date.
     */
    protected Date date;

    /**
     * Creates cached DNS response.
     *
     * @param response a DnsResponse
     * @param date     the date to expire response from cache
     */
    public DnsResponseCached(DnsResponse response, Date date) {
        this.response = response;
        this.date = date;
    }

    /**
     * Creates cached DNS response.
     *
     * @param response a DnsResponse
     * @param days     the number of days until expiration of response from cache
     */
    public DnsResponseCached(DnsResponse response, int days) {
        this.response = response;
        GregorianCalendar cal = new GregorianCalendar();
        cal.add(Calendar.DAY_OF_MONTH, days);
        this.date = cal.getTime();
    }

    /**
     * Gets DNS response from cache.
     *
     * @return a DnsResponse
     */
    public DnsResponse getResponse() {
        return response;
    }

    /**
     * Gets date that this DNS record will expire from cache.
     *
     * @return a Date
     */
    public Date getDate() {
        return date;
    }

}

