

package de.kaiserpfalzedv.office.tenant.api;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;

import java.util.UUID;

/**
 * @author rlichti {@literal <rlichti@kaiserpfalz-edv.de>}
 * @since 2016-09-20
 */
public class TenantImpl implements Tenant {
    private static final long serialVersionUID = 1065912149569391908L;

    private UUID id;
    private UUID tenant;
    private String key;

    private String displayName;
    private String fullName;

    @SuppressWarnings("unused")
    @Deprecated
    protected TenantImpl() {}


    @JsonCreator
    protected TenantImpl(
            @JsonProperty("tenant") final UUID tenant,
            @JsonProperty("id") final UUID id,
            @JsonProperty("key") final String key,
            @JsonProperty("displayName") final String displayName,
            @JsonProperty("fullName") final String fullName
    ) {
        this.tenant = tenant;
        this.id = id;
        this.key = key;
        this.displayName = displayName;
        this.fullName = fullName;
    }


    @Override
    public UUID getTenant() {
        return tenant;
    }

    @Override
    public String getDisplayName() {
        return displayName;
    }

    @Override
    public String getFullName() {
        return fullName;
    }

    @Override
    public String getKey() {
        return key;
    }

    @Override
    public int hashCode() {
        return new HashCodeBuilder(17, 37)
                .append(getId())
                .toHashCode();
    }

    @Override
    public UUID getId() {
        return id;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;

        if (!(o instanceof Tenant)) return false;

        Tenant tenant = (Tenant) o;

        return new EqualsBuilder()
                .append(getId(), tenant.getId())
                .isEquals();
    }

    @Override
    public String toString() {
        return new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE)
                .append("id", id)
                .append("tenant", tenant)
                .append("key", key)
                .append("displayName", displayName)
                .toString();
    }
}
