package com.l7tech.gateway.common.audit;

import com.l7tech.gateway.common.AsyncAdminMethods;
import com.l7tech.gateway.common.admin.Administrative;
import com.l7tech.gateway.common.cluster.ClusterProperty;
import com.l7tech.gateway.common.security.rbac.MethodStereotype;
import com.l7tech.gateway.common.security.rbac.Secured;
import com.l7tech.objectmodel.DeleteException;
import com.l7tech.objectmodel.EntityType;
import com.l7tech.objectmodel.FindException;
import com.l7tech.objectmodel.Goid;
import com.l7tech.objectmodel.UpdateException;
import com.l7tech.util.DeserializeSafe;
import com.l7tech.util.OpaqueId;
import com.l7tech.util.Pair;
import java.io.Serializable;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Date;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.logging.Level;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

@Transactional(propagation = Propagation.REQUIRED, rollbackFor = Throwable.class)
@Secured(types = EntityType.AUDIT_RECORD)
@Administrative
@DeserializeSafe
public interface AuditAdmin extends AsyncAdminMethods {
   Set<Integer> USER_DETAIL_MESSAGES = Collections.unmodifiableSet(
      new HashSet<>(
         Arrays.asList(
            AssertionMessages.USERDETAIL_WARNING.getId(),
            AssertionMessages.USERDETAIL_INFO.getId(),
            AssertionMessages.USERDETAIL_FINE.getId(),
            AssertionMessages.USERDETAIL_FINER.getId(),
            AssertionMessages.USERDETAIL_FINEST.getId()
         )
      )
   );

   @Transactional(readOnly = true)
   @Secured(stereotype = MethodStereotype.FIND_ENTITY)
   @Administrative(licensed = false)
   AuditRecord findByPrimaryKey(String var1, boolean var2) throws FindException;

   @Administrative(licensed = false, background = true)
   @Secured(stereotype = MethodStereotype.UNCHECKED_WIDE_OPEN)
   AsyncAdminMethods.JobId<AuditRecordHeader[]> findHeaders(AuditSearchCriteria var1) throws FindException;

   @Administrative(licensed = false, background = true)
   @Secured(stereotype = MethodStereotype.UNCHECKED_WIDE_OPEN)
   String getFindHeadersJobStatus(AsyncAdminMethods.JobId<AuditRecordHeader[]> var1);

   @Secured(stereotype = MethodStereotype.FIND_HEADERS)
   @Administrative(licensed = false, background = true)
   AuditRecordHeader[] getFindHeadersHeaderJobResult(AsyncAdminMethods.JobId<AuditRecordHeader[]> var1) throws FindException, AsyncAdminMethods.UnknownJobException, AsyncAdminMethods.JobStillActiveException;

   @Transactional(readOnly = true)
   @Secured(stereotype = MethodStereotype.FIND_ENTITIES)
   @Administrative(licensed = false, background = true)
   Map<String, Pair<byte[], byte[]>> getDigestsForAuditRecords(Collection<String> var1, boolean var2) throws FindException;

   @Transactional(readOnly = true)
   @Administrative(licensed = false, background = true)
   @Secured(stereotype = MethodStereotype.UNCHECKED_WIDE_OPEN)
   AsyncAdminMethods.JobId<Long> hasNewAudits(Date var1, Level var2);

   @Administrative(licensed = false, background = true)
   @Secured(stereotype = MethodStereotype.UNCHECKED_WIDE_OPEN)
   String getNewAuditsJobStatus(AsyncAdminMethods.JobId<Long> var1);

   @Administrative(licensed = false, background = true)
   @Secured(stereotype = MethodStereotype.UNCHECKED_WIDE_OPEN)
   AsyncAdminMethods.JobResult<Long> getNewAuditsJobResult(AsyncAdminMethods.JobId<Long> var1) throws AsyncAdminMethods.JobStillActiveException, AsyncAdminMethods.UnknownJobException;

   @Transactional(propagation = Propagation.SUPPORTS)
   @Administrative(licensed = false)
   @Secured(stereotype = MethodStereotype.UNCHECKED_WIDE_OPEN)
   Level serverMessageAuditThreshold();

   @Transactional(propagation = Propagation.SUPPORTS)
   @Administrative(licensed = false)
   @Secured(stereotype = MethodStereotype.UNCHECKED_WIDE_OPEN)
   Level serverDetailAuditThreshold();

   @Secured(stereotype = MethodStereotype.DELETE_MULTI)
   @Administrative(licensed = false)
   void deleteOldAuditRecords() throws DeleteException;

   @Secured(types = EntityType.AUDIT_RECORD, stereotype = MethodStereotype.DELETE_MULTI)
   void doAuditArchive();

   @Secured(stereotype = MethodStereotype.UNCHECKED_WIDE_OPEN)
   boolean isAuditArchiveEnabled();

   @Transactional(readOnly = true)
   @Secured(stereotype = MethodStereotype.FIND_ENTITY, types = EntityType.CLUSTER_PROPERTY)
   ClusterProperty getFtpAuditArchiveConfig();

   @Secured(stereotype = MethodStereotype.SAVE_OR_UPDATE, types = EntityType.CLUSTER_PROPERTY)
   void setFtpAuditArchiveConfig(ClusterProperty var1) throws UpdateException;

   @Transactional(readOnly = true)
   @Administrative(licensed = false)
   @Secured(stereotype = MethodStereotype.UNCHECKED_WIDE_OPEN)
   Date getLastAcknowledgedAuditDate();

   @Secured(stereotype = MethodStereotype.UNCHECKED_WIDE_OPEN)
   Date markLastAcknowledgedAuditDate();

   @Transactional(readOnly = true)
   @Secured(stereotype = MethodStereotype.FIND_ENTITIES)
   @Administrative(licensed = false)
   OpaqueId downloadAllAudits(long var1, long var3, Goid[] var5, int var6);

   @Transactional(readOnly = true)
   @Secured(stereotype = MethodStereotype.FIND_ENTITIES)
   @Administrative(licensed = false)
   AuditAdmin.DownloadChunk downloadNextChunk(OpaqueId var1);

   @Transactional(propagation = Propagation.SUPPORTS)
   @Administrative(licensed = false)
   @Secured(stereotype = MethodStereotype.UNCHECKED_WIDE_OPEN)
   int serverMinimumPurgeAge();

   @Transactional(readOnly = true)
   @Administrative(licensed = false, background = true)
   @Secured(stereotype = MethodStereotype.UNCHECKED_WIDE_OPEN)
   boolean isSigningEnabled() throws FindException;

   @Transactional(readOnly = true)
   @Administrative(licensed = false, background = true)
   @Secured(stereotype = MethodStereotype.UNCHECKED_WIDE_OPEN)
   int getMaxDigestRecords();

   @Transactional(readOnly = true)
   @Secured(stereotype = MethodStereotype.UNCHECKED_WIDE_OPEN)
   boolean isAuditViewerPolicyAvailable();

   @Secured(stereotype = MethodStereotype.ENTITY_OPERATION, otherOperation = "audit-viewer policy", relevantArg = 0)
   String invokeAuditViewerPolicyForMessage(Goid var1, boolean var2) throws FindException, AuditViewerPolicyNotAvailableException;

   @Secured(stereotype = MethodStereotype.UNCHECKED_WIDE_OPEN, otherOperation = "audit-viewer policy")
   String invokeAuditViewerPolicyForMessage(String var1, String var2, boolean var3) throws AuditViewerPolicyNotAvailableException;

   @Secured(stereotype = MethodStereotype.ENTITY_OPERATION, otherOperation = "audit-viewer policy", relevantArg = 0)
   String invokeAuditViewerPolicyForDetail(Goid var1, long var2) throws FindException, AuditViewerPolicyNotAvailableException;

   @Transactional(readOnly = true)
   @Secured(stereotype = MethodStereotype.UNCHECKED_WIDE_OPEN)
   Collection<String> getAllEntityClassNames();

   @Transactional(propagation = Propagation.SUPPORTS)
   @Secured(stereotype = MethodStereotype.UNCHECKED_WIDE_OPEN)
   int getSystemLogRefresh();

   @Secured(types = EntityType.LOG_SINK, stereotype = MethodStereotype.SET_PROPERTY_BY_UNIQUE_ATTRIBUTE)
   @Transactional(readOnly = true)
   String getExternalAuditsSchema(String var1, String var2, String var3);

   @Secured(types = EntityType.LOG_SINK, stereotype = MethodStereotype.SET_PROPERTY_BY_UNIQUE_ATTRIBUTE)
   @Transactional(readOnly = true)
   AsyncAdminMethods.JobId<String> testAuditSinkSchema(String var1, String var2, String var3);

   @Secured(types = EntityType.LOG_SINK, stereotype = MethodStereotype.SET_PROPERTY_BY_UNIQUE_ATTRIBUTE)
   @Transactional(readOnly = true)
   AsyncAdminMethods.JobId<String> createExternalAuditDatabaseTables(String var1, String var2, String var3, String var4, String var5);

   final class DownloadChunk implements Serializable {
      public final long auditsDownloaded;
      public final long approxTotalAudits;
      public final byte[] chunk;
      static final long serialVersionUID = -8520106819181494299L;

      public DownloadChunk(long var1, long var3, byte[] var5) {
         this.auditsDownloaded = var1;
         this.approxTotalAudits = var3;
         this.chunk = var5;
      }
   }
}
