package be.iminds.ilabt.jfed.lowlevel.api.user_spec;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.Collection;
import java.util.Objects;

/**
 * User: twalcari
 * Date: 8/4/2015
 * Time: 16:40
 */
public class LoginSpec extends UserSpec {
    @Nullable
    private final String loginName;

    public LoginSpec(UserSpec orig, @Nullable String loginName) {
        super(orig);
        this.loginName = loginName;
    }

    public LoginSpec(String urn, @Nullable String loginName) {
        super(urn);
        this.loginName = loginName;
    }

    public LoginSpec(@Nonnull String urn, @Nullable String sshKey, @Nullable String loginName) {
        super(urn, sshKey);
        this.loginName = loginName;
    }

    public LoginSpec(@Nonnull String urn, @Nullable Collection<String> sshKeys, @Nullable String loginName) {
        super(urn, sshKeys);
        this.loginName = loginName;
    }

    @Nullable
    public String getLoginName() {
        return loginName;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        if (!super.equals(o)) return false;

        LoginSpec loginSpec = (LoginSpec) o;

        return !(loginName != null ? !Objects.equals(loginName, loginSpec.loginName) : loginSpec.loginName != null);

    }

    @Override
    public int hashCode() {
        int result = super.hashCode();
        result = 31 * result + (loginName != null ? loginName.hashCode() : 0);
        return result;
    }
}
