/*
 * Copyright 2018 Scytl Secure Electronic Voting SA
 *
 * All rights reserved
 *
 * See our extended copyright notice in *file 'Copyright.txt' which is part of this source code package
 */
package com.scytl.products.ov.ea.domain.model.extendedauthentication;

import javax.ejb.Local;
import java.util.List;
import java.util.Optional;

import com.scytl.products.ov.commons.beans.exceptions.ApplicationException;
import com.scytl.products.ov.commons.domain.model.BaseRepository;

/**
 * Provides operations on the election event translation repository.
 */
@Local
public interface ExtendedAuthenticationRepository extends BaseRepository<ExtendedAuthentication, String> {

    /**
     * Retrieves an Extended Authentication for later update (with locking).
     * 
     * @param tenantId
     *            The Tenant Id.
     * @param authId
     *            The Auth Id.
     * @param electionEventId
     *            The Election Event Id.
     * @return The retrieved Extended Authentication entity.
     * @throws ApplicationException
     *             An exception raised if the locking was unsuccessful.
     */
    Optional<ExtendedAuthentication> getForUpdate(String tenantId, String authId, String electionEventId)
            throws ApplicationException;

    /**
     * Retrieves an Extended Authentication just for read (without locking and detached).
     * 
     * @param tenantId
     *            The Tenant Id.
     * @param authId
     *            The Auth Id.
     * @param electionEventId
     *            The Election Event Id.
     * @return The retrieved and detached Extended Authentication entity.
     */
    Optional<ExtendedAuthentication> getForRead(String tenantId, String authId, String electionEventId);

    /**
     * Deletes an Extended Authentication entity.
     * 
     * @param extendedAuthentication
     *            The Extended Authentication entity to be deleted.
     */
    void delete(ExtendedAuthentication extendedAuthentication);

    /**
     * Find all Voting cards associated with failed extended authentications (?)
     * @param tenantId the Tenant identifier
     * @param electionEventId the Election Event identifier
     * @param maxAllowedNumberOfAttempts the max number of allowed auth attempts
     */
    List<ExtendedAuthentication> findAllExceededExtendedAuthentication(final String tenantId,
                                                                       final String electionEventId,
                                                                       final Integer maxAllowedNumberOfAttempts);
}
