package ch.pizzalemon.android.model;

import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;

import java.io.Serializable;

import ch.pizzalemon.android.helper.DateTimeHelper;

/**
 * Created by cimenmus on 26/09/2017.
 */

public class CustomerTokenModel implements Serializable {

    @Expose @SerializedName("customer_token") private String token;
    @Expose @SerializedName("token_death_time") private String expiresIn;
    @Expose @SerializedName("refresh_token") private String refreshToken;

    private StoreModel storeOfToken;

    public boolean isCustomerTokenAlive(){
        long millis7days = 86400000 * 7;
        return DateTimeHelper.getMillisFromDateString(expiresIn) - System.currentTimeMillis() >= millis7days;
    }

    public void checkNull(){

        if(token == null)
            token = "";

        if(expiresIn == null)
            expiresIn = "";

        if(refreshToken == null)
            refreshToken = "";
    }

    public String getToken() {
        return token;
    }

    public void setToken(String token) {
        this.token = token;
    }

    public String getExpiresIn() {
        return expiresIn;
    }

    public void setExpiresIn(String expiresIn) {
        this.expiresIn = expiresIn;
    }

    public String getRefreshToken() {
        return refreshToken;
    }

    public void setRefreshToken(String refreshToken) {
        this.refreshToken = refreshToken;
    }

    public StoreModel getStoreOfToken() {
        if(storeOfToken == null){
            storeOfToken = new StoreModel();
        }
        return storeOfToken;
    }

    public void setStoreOfToken(StoreModel storeOfToken) {
        this.storeOfToken = storeOfToken;
    }
}
