/*
 * Decompiled with CFR 0.152.
 * 
 * Could not load the following classes:
 *  com.l7tech.gateway.common.audit.Audit
 *  com.l7tech.gateway.common.audit.AuditFactory
 *  com.l7tech.gateway.common.service.PublishedService
 *  com.l7tech.gateway.common.transport.ResolutionConfiguration
 *  com.l7tech.message.Message
 */
package com.l7tech.server.service.resolution;

import com.l7tech.gateway.common.audit.Audit;
import com.l7tech.gateway.common.audit.AuditFactory;
import com.l7tech.gateway.common.service.PublishedService;
import com.l7tech.gateway.common.transport.ResolutionConfiguration;
import com.l7tech.message.Message;
import com.l7tech.server.service.resolution.Result;
import com.l7tech.server.service.resolution.ServiceResolutionException;
import com.l7tech.server.service.resolution.ServiceResolutionHelper;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.logging.Logger;

public abstract class ServiceResolver<T> {
    protected final Logger logger = Logger.getLogger(this.getClass().getName());
    protected final Audit auditor;
    protected static final String SUFFIX_VALUE;
    protected final String PROP_BASE = this.getClass().getName();
    protected final String PROP_VALUE = this.PROP_BASE + l[1];
    private final String a;
    protected ServiceResolutionHelper serviceResolutionHelper;
    private static final String[] l;

    public ServiceResolver(AuditFactory auditFactory) {
        this.auditor = auditFactory.newInstance((Object)this, this.logger);
        this.a = this.getClass().getSimpleName();
    }

    public String getSimpleName() {
        return this.a;
    }

    public void configure(ResolutionConfiguration resolutionConfiguration) {
    }

    public final void serviceCreated(PublishedService publishedService) throws ServiceResolutionException {
        List<T> list = this.buildTargetValues(publishedService);
        this.updateServiceValues(publishedService, list);
    }

    public void serviceUpdated(PublishedService publishedService) throws ServiceResolutionException {
    }

    public void serviceDeleted(PublishedService publishedService) {
    }

    public abstract Result resolve(Map<String, Object> var1, Collection<PublishedService> var2) throws ServiceResolutionException;

    public abstract void populateResolutionParameters(Message var1, Map<String, Object> var2) throws ServiceResolutionException;

    public Collection<Map<String, Object>> generateResolutionParameters(PublishedService publishedService, Collection<Map<String, Object>> collection) throws ServiceResolutionException {
        HashSet<T> hashSet = new HashSet<T>(this.buildTargetValues(publishedService));
        try {
            if (hashSet.isEmpty()) {
                return collection;
            }
        }
        catch (ServiceResolutionException serviceResolutionException) {
            throw ServiceResolver.b(serviceResolutionException);
        }
        ArrayList<Map<String, Object>> arrayList = new ArrayList<Map<String, Object>>(collection.size() * hashSet.size());
        for (Object e10 : hashSet) {
            for (Map<String, Object> map : collection) {
                HashMap<String, Object> hashMap = new HashMap<String, Object>(map);
                hashMap.put(this.PROP_VALUE, e10);
                arrayList.add(hashMap);
            }
        }
        return arrayList;
    }

    public abstract boolean usesMessageContent();

    protected abstract List<T> buildTargetValues(PublishedService var1) throws ServiceResolutionException;

    protected abstract void updateServiceValues(PublishedService var1, List<T> var2);

    public void setServiceResolutionHelper(ServiceResolutionHelper serviceResolutionHelper) {
        this.serviceResolutionHelper = serviceResolutionHelper;
    }

    private static ServiceResolutionException b(ServiceResolutionException serviceResolutionException) {
        return serviceResolutionException;
    }

    /*
     * Enabled aggressive block sorting
     */
    static {
        String[] stringArray = new String[2];
        int n2 = 0;
        String string = "]\"\\=F&\u0006]\"\\=F&";
        int n3 = "]\"\\=F&\u0006]\"\\=F&".length();
        int n4 = 6;
        int n5 = -1;
        while (true) {
            int n6 = ++n5;
            stringArray[n2++] = ServiceResolver.a(122, ServiceResolver.c(string.substring(n6, n6 + n4)));
            if ((n5 += n4) >= n3) {
                l = stringArray;
                SUFFIX_VALUE = l[0];
                return;
            }
            n4 = string.charAt(n5);
        }
    }

    private static char[] c(String string) {
        char[] cArray = string.toCharArray();
        if (cArray.length < 2) {
            cArray = cArray;
            cArray[0] = (char)(cArray[0] ^ 0x30);
        }
        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 -> 9;
                    case 1 -> 46;
                    case 2 -> 71;
                    case 3 -> 43;
                    case 4 -> 73;
                    case 5 -> 57;
                    default -> 48;
                })));
                ++n3;
                n4 = n4;
            } while (n4 > n3);
        }
        return new String(cArray2).intern();
    }
}

