/*
 * Decompiled with CFR 0.152.
 * 
 * Could not load the following classes:
 *  com.l7tech.gateway.common.audit.AuditConfiguration
 *  com.l7tech.gateway.common.cluster.ClusterProperty
 *  com.l7tech.gateway.common.transport.ftp.FtpUtils
 *  com.l7tech.objectmodel.DeleteException
 *  com.l7tech.objectmodel.Entity
 *  com.l7tech.objectmodel.EntityHeader
 *  com.l7tech.objectmodel.EntityType
 *  com.l7tech.objectmodel.FindException
 *  com.l7tech.objectmodel.Goid
 *  com.l7tech.objectmodel.ObjectModelException
 *  com.l7tech.objectmodel.PersistentEntity
 *  com.l7tech.objectmodel.SaveException
 *  com.l7tech.objectmodel.UpdateException
 *  com.l7tech.policy.Policy
 *  com.l7tech.util.CollectionUtils
 *  com.l7tech.util.Option
 *  jakarta.inject.Inject
 *  org.jetbrains.annotations.NotNull
 *  org.jetbrains.annotations.Nullable
 *  org.springframework.transaction.PlatformTransactionManager
 *  org.springframework.transaction.annotation.Propagation
 *  org.springframework.transaction.annotation.Transactional
 *  org.springframework.transaction.support.TransactionCallback
 *  org.springframework.transaction.support.TransactionTemplate
 */
package com.l7tech.server.audit;

import com.l7tech.gateway.common.audit.AuditConfiguration;
import com.l7tech.gateway.common.cluster.ClusterProperty;
import com.l7tech.gateway.common.transport.ftp.FtpUtils;
import com.l7tech.objectmodel.DeleteException;
import com.l7tech.objectmodel.Entity;
import com.l7tech.objectmodel.EntityHeader;
import com.l7tech.objectmodel.EntityType;
import com.l7tech.objectmodel.FindException;
import com.l7tech.objectmodel.Goid;
import com.l7tech.objectmodel.ObjectModelException;
import com.l7tech.objectmodel.PersistentEntity;
import com.l7tech.objectmodel.SaveException;
import com.l7tech.objectmodel.UpdateException;
import com.l7tech.policy.Policy;
import com.l7tech.server.audit.AuditConfigurationManager;
import com.l7tech.server.audit.l;
import com.l7tech.server.cluster.ClusterPropertyManager;
import com.l7tech.server.policy.PolicyManager;
import com.l7tech.util.CollectionUtils;
import com.l7tech.util.Option;
import jakarta.inject.Inject;
import java.io.IOException;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.support.TransactionCallback;
import org.springframework.transaction.support.TransactionTemplate;

@Transactional(propagation=Propagation.REQUIRED, rollbackFor={Throwable.class})
public class AuditConfigurationManagerImpl
implements AuditConfigurationManager {
    @Inject
    private ClusterPropertyManager clusterPropertyManager;
    @Inject
    private PolicyManager policyManager;
    @Inject
    private PlatformTransactionManager transactionManager;
    private static final String[] a;

    public AuditConfigurationManagerImpl(PolicyManager policyManager, ClusterPropertyManager clusterPropertyManager, PlatformTransactionManager platformTransactionManager) {
        this.clusterPropertyManager = clusterPropertyManager;
        this.policyManager = policyManager;
        this.transactionManager = platformTransactionManager;
    }

    @Override
    @Nullable
    public AuditConfiguration findByPrimaryKey(@Nullable Goid goid) throws FindException {
        block4: {
            try {
                try {
                    if (goid != null && !goid.equals((Object)AuditConfiguration.ENTITY_ID)) break block4;
                }
                catch (FindException findException) {
                    throw AuditConfigurationManagerImpl.a((ObjectModelException)((Object)findException));
                }
                return this.a();
            }
            catch (FindException findException) {
                throw AuditConfigurationManagerImpl.a((ObjectModelException)((Object)findException));
            }
        }
        return null;
    }

    public Collection<EntityHeader> findAllHeaders() throws FindException {
        return CollectionUtils.list((Object[])new EntityHeader[]{new EntityHeader(AuditConfiguration.ENTITY_ID, EntityType.AUDIT_CONFIG, AuditConfiguration.ENTITY_NAME, "")});
    }

    public Collection<EntityHeader> findAllHeaders(int n2, int n3) throws FindException {
        return this.findAllHeaders();
    }

    public Collection<AuditConfiguration> findAll() throws FindException {
        return CollectionUtils.list((Object[])new AuditConfiguration[]{this.a()});
    }

    public Class<? extends Entity> getImpClass() {
        return AuditConfiguration.class;
    }

    public Goid save(AuditConfiguration auditConfiguration) throws SaveException {
        try {
            this.update(auditConfiguration);
        }
        catch (UpdateException updateException) {
            throw new SaveException(updateException.getMessage(), (Throwable)updateException);
        }
        return AuditConfiguration.ENTITY_ID;
    }

    /*
     * Enabled aggressive block sorting
     * Enabled unnecessary exception pruning
     * Enabled aggressive exception aggregation
     */
    public void save(Goid goid, AuditConfiguration auditConfiguration) throws SaveException {
        try {
            if (!AuditConfiguration.ENTITY_ID.equals((Object)goid)) throw new UnsupportedOperationException();
            try {
                this.update(auditConfiguration);
                return;
            }
            catch (UpdateException updateException) {
                throw new SaveException(updateException.getMessage(), (Throwable)updateException);
            }
        }
        catch (SaveException saveException) {
            throw AuditConfigurationManagerImpl.a((ObjectModelException)((Object)saveException));
        }
    }

    public Integer getVersion(Goid goid) throws FindException {
        return 0;
    }

    public Map<Goid, Integer> findVersionMap() throws FindException {
        return new HashMap<Goid, Integer>();
    }

    public void delete(AuditConfiguration auditConfiguration) throws DeleteException {
        throw new UnsupportedOperationException();
    }

    @Nullable
    public AuditConfiguration getCachedEntity(Goid goid, int n2) throws FindException {
        return null;
    }

    public Class<? extends Entity> getInterfaceClass() {
        return AuditConfiguration.class;
    }

    public EntityType getEntityType() {
        return EntityType.AUDIT_CONFIG;
    }

    public String getTableName() {
        return "";
    }

    @Nullable
    public AuditConfiguration findByUniqueName(String string) throws FindException {
        try {
            if (AuditConfiguration.ENTITY_NAME.equals(string)) {
                return this.a();
            }
        }
        catch (FindException findException) {
            throw AuditConfigurationManagerImpl.a((ObjectModelException)((Object)findException));
        }
        return null;
    }

    public void delete(Goid goid) throws DeleteException, FindException {
        throw new UnsupportedOperationException();
    }

    public void update(AuditConfiguration auditConfiguration) throws UpdateException {
        Option option = (Option)new TransactionTemplate(this.transactionManager).execute((TransactionCallback)new l(this, auditConfiguration));
        try {
            if (option.isSome()) {
                throw (UpdateException)((Object)option.some());
            }
        }
        catch (UpdateException updateException) {
            throw AuditConfigurationManagerImpl.a((ObjectModelException)((Object)updateException));
        }
    }

    private Policy a(@Nullable Goid goid) throws FindException {
        Policy policy = (Policy)this.policyManager.findByPrimaryKey(goid);
        try {
            if (policy == null) {
                throw new FindException(a[9] + String.valueOf(goid));
            }
        }
        catch (FindException findException) {
            throw AuditConfigurationManagerImpl.a((ObjectModelException)((Object)findException));
        }
        return policy;
    }

    private Policy a(@Nullable String string) throws FindException {
        Policy policy = this.policyManager.findByGuid(string);
        try {
            if (policy == null) {
                throw new FindException(a[6] + string);
            }
        }
        catch (FindException findException) {
            throw AuditConfigurationManagerImpl.a((ObjectModelException)((Object)findException));
        }
        return policy;
    }

    private void a(@NotNull String string, String string2) throws ObjectModelException {
        ClusterProperty clusterProperty;
        block11: {
            block12: {
                try {
                    if (string == null) {
                        AuditConfigurationManagerImpl.a(0);
                    }
                }
                catch (ObjectModelException objectModelException) {
                    throw AuditConfigurationManagerImpl.a(objectModelException);
                }
                clusterProperty = (ClusterProperty)this.clusterPropertyManager.findByUniqueName(string);
                try {
                    try {
                        if (string2 != null) break block11;
                        if (clusterProperty == null) break block12;
                    }
                    catch (ObjectModelException objectModelException) {
                        throw AuditConfigurationManagerImpl.a(objectModelException);
                    }
                    this.clusterPropertyManager.delete((PersistentEntity)clusterProperty);
                }
                catch (ObjectModelException objectModelException) {
                    throw AuditConfigurationManagerImpl.a(objectModelException);
                }
            }
            return;
        }
        if (clusterProperty == null) {
            clusterProperty = new ClusterProperty(string, string2);
            Goid goid = this.clusterPropertyManager.save((PersistentEntity)clusterProperty);
            try {
                if (!goid.equals((Object)clusterProperty.getGoid())) {
                    clusterProperty.setGoid(goid);
                }
            }
            catch (ObjectModelException objectModelException) {
                throw AuditConfigurationManagerImpl.a(objectModelException);
            }
        }
        clusterProperty.setValue(string2);
        this.clusterPropertyManager.update((PersistentEntity)clusterProperty);
    }

    @Nullable
    public AuditConfiguration findByHeader(EntityHeader entityHeader) throws FindException {
        return this.findByPrimaryKey(entityHeader.getGoid());
    }

    public List<AuditConfiguration> findPagedMatching(int n2, int n3, @Nullable String string, @Nullable Boolean bl2, @Nullable Map<String, List<Object>> map) throws FindException {
        return CollectionUtils.list((Object[])new AuditConfiguration[]{this.a()});
    }

    private AuditConfiguration a() throws FindException {
        try {
            AuditConfiguration auditConfiguration = new AuditConfiguration();
            String[] stringArray = a;
            String string = this.clusterPropertyManager.getProperty(stringArray[0]);
            try {
                if (string != null) {
                    auditConfiguration.setAlwaysSaveInternal(Boolean.parseBoolean(string));
                }
            }
            catch (FindException findException) {
                throw AuditConfigurationManagerImpl.a((ObjectModelException)((Object)findException));
            }
            stringArray = a;
            String string2 = this.clusterPropertyManager.getProperty(stringArray[1]);
            try {
                if (string2 != null) {
                    auditConfiguration.setSinkPolicyGoid(this.a(string2).getGoid());
                }
            }
            catch (FindException findException) {
                throw AuditConfigurationManagerImpl.a((ObjectModelException)((Object)findException));
            }
            stringArray = a;
            String string3 = this.clusterPropertyManager.getProperty(stringArray[7]);
            try {
                if (string3 != null) {
                    auditConfiguration.setLookupPolicyGoid(this.a(string3).getGoid());
                }
            }
            catch (FindException findException) {
                throw AuditConfigurationManagerImpl.a((ObjectModelException)((Object)findException));
            }
            auditConfiguration.setFtpClientConfig(FtpUtils.deserialize((String)this.clusterPropertyManager.getProperty(a[5])));
            return auditConfiguration;
        }
        catch (FindException | IOException | ClassNotFoundException throwable) {
            throw new FindException(throwable.getMessage(), throwable);
        }
    }

    private static /* synthetic */ void a(int n2) {
        String[] stringArray = a;
        throw new IllegalArgumentException(String.format(stringArray[3], stringArray[4], stringArray[8], stringArray[2]));
    }

    private static ObjectModelException a(ObjectModelException objectModelException) {
        return objectModelException;
    }

    /*
     * Unable to fully structure code
     */
    static {
        block10: {
            block9: {
                var5 = new String[10];
                var3_1 = 0;
                var2_2 = "qbxWO0eyyw\u0010ZraqnomZhsYyh[Ipw|\u0016qbxWO0eyyw\u0010Kqzyte\u0010\\k\u007ft\u0015egx_O{U|boJ^lFbxl[Ijo>Qe{KV{xd7zQI>V^xhpNrz0g}LZssdrn\u001e\u001c;e77sX\u001b;e>2o\u001eVked7rQO>tu7rKWr\u0003{re\u0019qbxWO0wbttWM{d>qhN\u0015}y~quY\u0017@xpWXg6~xh\u001e]qc~s<YNwr*7\u0018qbxWO0z\u007fxwKK0f\u007f{u]B0qe~x";
                var4_3 = "qbxWO0eyyw\u0010ZraqnomZhsYyh[Ipw|\u0016qbxWO0eyyw\u0010Kqzyte\u0010\\k\u007ft\u0015egx_O{U|boJ^lFbxl[Ijo>Qe{KV{xd7zQI>V^xhpNrz0g}LZssdrn\u001e\u001c;e77sX\u001b;e>2o\u001eVked7rQO>tu7rKWr\u0003{re\u0019qbxWO0wbttWM{d>qhN\u0015}y~quY\u0017@xpWXg6~xh\u001e]qc~s<YNwr*7\u0018qbxWO0z\u007fxwKK0f\u007f{u]B0qe~x".length();
                var1_4 = 29;
                var0_5 = -1;
lbl7:
                // 2 sources

                while (true) {
                    v0 = 99;
                    v1 = ++var0_5;
                    v2 = var2_2.substring(v1, v1 + var1_4);
                    v3 = -1;
                    break block9;
                    break;
                }
lbl13:
                // 1 sources

                while (true) {
                    var5[var3_1++] = AuditConfigurationManagerImpl.a(v0, AuditConfigurationManagerImpl.b(v2));
                    if ((var0_5 += var1_4) < var4_3) {
                        var1_4 = var2_2.charAt(var0_5);
                        ** continue;
                    }
                    var2_2 = "U^W7q\u000fDSRR7n]B@TH7|MT_E\u0015Yh\\YBrUv{QWCC[ltW^{PTyz]B\u007f\\Jt\u0015f^Vq~A\u0010X^N8{WEXU\u001aqy\u0002\u0010";
                    var4_3 = "U^W7q\u000fDSRR7n]B@TH7|MT_E\u0015Yh\\YBrUv{QWCC[ltW^{PTyz]B\u007f\\Jt\u0015f^Vq~A\u0010X^N8{WEXU\u001aqy\u0002\u0010".length();
                    var1_4 = 53;
                    var0_5 = -1;
lbl22:
                    // 2 sources

                    while (true) {
                        v0 = 69;
                        v4 = ++var0_5;
                        v2 = var2_2.substring(v4, v4 + var1_4);
                        v3 = 0;
                        break block9;
                        break;
                    }
                    break;
                }
lbl28:
                // 1 sources

                while (true) {
                    var5[var3_1++] = AuditConfigurationManagerImpl.a(v0, AuditConfigurationManagerImpl.b(v2));
                    if ((var0_5 += var1_4) < var4_3) {
                        var1_4 = var2_2.charAt(var0_5);
                        ** continue;
                    }
                    break block10;
                    break;
                }
            }
            switch (v3) {
                default: {
                    ** continue;
                }
                ** case 0:
lbl39:
                // 1 sources

                ** continue;
            }
        }
        AuditConfigurationManagerImpl.a = var5;
    }

    private static char[] b(String string) {
        char[] cArray = string.toCharArray();
        if (cArray.length < 2) {
            cArray = cArray;
            cArray[0] = (char)(cArray[0] ^ 0x75);
        }
        return cArray;
    }

    /*
     * Handled impossible loop by duplicating code
     * Enabled aggressive block sorting
     */
    private static String a(int n2, char[] cArray) {
        char[] cArray2;
        block11: {
            int n3;
            int n4;
            int n5;
            block10: {
                n5 = n2;
                cArray2 = cArray;
                n4 = cArray.length;
                n3 = 0;
                if (!true) break block10;
                n4 = n4;
                if (n4 <= n3) break block11;
            }
            do {
                n5 = n5;
                cArray2 = cArray2;
                int n6 = n3;
                cArray2[n6] = (char)(cArray2[n6] ^ (n5 ^ (switch (n3 % 7) {
                    case 0 -> 115;
                    case 1 -> 116;
                    case 2 -> 127;
                    case 3 -> 93;
                    case 4 -> 88;
                    case 5 -> 125;
                    default -> 117;
                })));
                ++n3;
                n4 = n4;
            } while (n4 > n3);
        }
        return new String(cArray2).intern();
    }
}

