package be.iminds.ilabt.jfed.lowlevel.user;

import be.iminds.ilabt.jfed.fedmon.webapi.service.json.Server;
import be.iminds.ilabt.jfed.lowlevel.GeniUser;
import be.iminds.ilabt.jfed.lowlevel.userloginmodel.InvalidLoginException;
import be.iminds.ilabt.jfed.util.GeniUrn;

import javax.annotation.Nullable;
import java.security.cert.X509Certificate;
import java.util.Date;
import java.util.List;

/**
 * This class contains basic info about the credentials the user provided.
 * <p>
 * The implementation classes extract the various info from the credentials file the user provided
 * <p>
 * User: twalcari
 * Date: 7/14/2016
 * Time: 14:49
 */
public interface UserLoginInfo {

    boolean isUserAndAuthorityProvidedSeperately();

    /**
     * @return true if all necessary info is present.
     * However, it is still possible that the private key is locked (check with isUnlocked for this).
     */
    boolean isValid();

    /**
     * @return true if the private key is present and unlocked
     */
    boolean isUnlocked();

    GeniUser login(char[] password) throws InvalidLoginException;

    @Nullable
    GeniUrn getUserUrn();

    @Nullable
    Date getExpirationDate();

    @Nullable
    List<X509Certificate> getCertificateChain();

    @Nullable
    String getCertificateContent();

    /**
     * @return Human-readable string of the UserLoginInfo-type (ex. 'Manual Info')
     */
    String getUserLoginTypeName();

    Server getUserAuthorityServer();

    boolean equals(UserLoginInfo o);

    /**
     * @return When the parsing of the UserLoginInfo failed, this will contain a message with the error
     */
    @Nullable
    String getError();
}
