package be.iminds.ilabt.jfed.lowlevel;

import be.iminds.ilabt.jfed.fedmon.webapi.service.json.Server;
import be.iminds.ilabt.jfed.util.GeniUrn;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.io.File;
import java.security.PrivateKey;
import java.security.PublicKey;
import java.security.cert.X509Certificate;
import java.util.List;

/**
 * GeniUser represents a logged-in user
 */
public interface GeniUser {
    /**
     * @return The Private key of the user setting up the SSL connection.
     * <p>
     * In speaksfor case, this is the speaker, not to spoken for user.
     */
    @Nonnull
    PrivateKey getPrivateKey();

    /**
     * @return The public key of the user setting up the SSL connection.
     * <p>
     * In speaksfor case, this is the speaker, not to spoken for user.
     */
    @Nonnull
    PublicKey getPublicKey();

    /**
     * @return The X509 certificate chain of the user setting up the SSL connection.
     * <p>
     * In speaksfor case, this is the speaker, not to spoken for user.
     */
    @Nonnull
    List<X509Certificate> getClientCertificateChain();

    /**
     * @return The authority server of the user setting up the SSL connection.
     * <p>
     * In speaksfor case, this is the speaker, not to spoken for user.
     *
     * The only case this can be null is when the authority is not known (yet) by jFed.
     * This is only possible when using a new authority to the scanner or probe.
     */
    @Nullable
    Server getUserAuthorityServer();

    /**
     * @return The URN of the user setting up the SSL connection, in string format.
     * <p>
     * In speaksfor case, this is the speaker, not to spoken for user.
     */
    @Nonnull
    String getUserUrnString();

    /**
     * @return The URN of the user setting up the SSL connection. In speaksfor case, this is the speaker, not to spoken for user.
     */
    @Nonnull
    GeniUrn getUserUrn();


    /**
     * @return The file containing the private key of the user setting up the SSL connection.
     * <p>
     * In speaksfor case, this is the speaker, not to spoken for user.
     */
    @Nullable
    File getPrivateKeyFile();

    /**
     * @return The file containing the certificate(s) of the user setting up the SSL connection.
     * <p>
     * In speaksfor case, this is the speaker, not to spoken for user.
     */
    @Nullable
    File getCertificateFile();


    /*
    * example getPublicKey implementation:

    @Override
    public PublicKey getPublicKey() {
        List<X509Certificate> certificateChain = getClientCertificateChain();
        if (certificateChain == null || certificateChain.isEmpty())
            return null;
        return certificateChain.get(0).getPublicKey();
    }
    * */
}
