package com.inet.dashboard.openweathermap;

import java.util.Locale;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;

/**
 * Wrapper of the settings that is used to identify the refresh task to update the weather data
 */
public class WidgetSettings {

    private @Nonnull String apiKey;
    private @Nonnull String location;
    private @Nonnull Units  units;
    private @Nonnull Locale locale;

    /**
     * Creates the instance
     * @param apiKey the api key from openweathermap.org
     * @param location the location the weather should be loaded for
     * @param units the units of the values
     * @param locale the client lcoale
     */
    public WidgetSettings( @Nonnull String apiKey, @Nonnull String location, @Nonnull Units units, @Nonnull Locale locale ) {
        this.apiKey = apiKey;
        this.location = location;
        this.units = units;
        this.locale = locale;
    }

    /**
     * Returns the api key from openweathermap.org
     * @return the api key from openweathermap.org
     */
    public String getApiKey() {
        return apiKey;
    }

    /**
     * Returns the client locale
     * @return the client locale
     */
    public Locale getLocale() {
        return locale;
    }

    /**
     * Returns the location the weather should be loaded for
     * @return the location the weather should be loaded for
     */
    public String getLocation() {
        return location;
    }

    /**
     * Returns the units of the values
     * @return the units of the values
     */
    public Units getUnits() {
        return units;
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public int hashCode() {
        final int prime = 31;
        int result = 1;
        result = prime * result + ((locale == null) ? 0 : locale.hashCode());
        result = prime * result + ((location == null) ? 0 : location.hashCode());
        result = prime * result + ((units == null) ? 0 : units.hashCode());
        return result;
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public boolean equals( @Nullable Object obj ) {
        if( this == obj ) {
            return true;
        }
        if( obj == null ) {
            return false;
        }
        if( getClass() != obj.getClass() ) {
            return false;
        }
        WidgetSettings other = (WidgetSettings)obj;
        if( !locale.equals( other.locale ) ) {
            return false;
        }
        if( !location.equals( other.location ) ) {
            return false;
        }
        if( units != other.units ) {
            return false;
        }
        return true;
    }

}
