/*
 * Decompiled with CFR 0.152.
 * 
 * Could not load the following classes:
 *  com.l7tech.policy.variable.Syntax$SyntaxErrorHandler
 *  com.l7tech.util.CollectionUtils
 *  com.l7tech.util.DateUtils
 *  com.l7tech.util.DateUtils$InvalidPatternException
 *  com.l7tech.util.ExceptionUtils
 */
package com.l7tech.server.policy.variable;

import com.l7tech.policy.variable.Syntax;
import com.l7tech.server.policy.variable.ExpandVariables;
import com.l7tech.util.CollectionUtils;
import com.l7tech.util.DateUtils;
import com.l7tech.util.ExceptionUtils;
import java.util.Date;
import java.util.Map;
import java.util.TimeZone;

public class DateTimeSelector
implements ExpandVariables.Selector<Date> {
    private static final String a;
    private static final String b;
    private static final String c;
    private static final String d;
    private static final String e;
    private static final String f;
    static final Map<String, String> g;
    private static final String[] h;

    @Override
    public ExpandVariables.Selector.Selection select(String string, Date date, String string2, Syntax.SyntaxErrorHandler syntaxErrorHandler, boolean bl2) {
        try {
            if (h[4].equalsIgnoreCase(string2)) {
                return new ExpandVariables.Selector.Selection(date.getTime());
            }
        }
        catch (IllegalArgumentException illegalArgumentException) {
            throw DateTimeSelector.a(illegalArgumentException);
        }
        try {
            if (h[1].equalsIgnoreCase(string2)) {
                return new ExpandVariables.Selector.Selection(date.getTime() / 1000L);
            }
        }
        catch (IllegalArgumentException illegalArgumentException) {
            throw DateTimeSelector.a(illegalArgumentException);
        }
        try {
            TimeZone timeZone = DateUtils.getTimeZone((String)string2);
            if (timeZone != null) {
                return new ExpandVariables.Selector.Selection(DateUtils.getFormattedString((Date)date, (TimeZone)timeZone, (String)DateUtils.ISO8601_PATTERN));
            }
            try {
                if (g.keySet().contains(string2.toLowerCase())) {
                    return new ExpandVariables.Selector.Selection(DateUtils.getFormattedString((Date)date, (TimeZone)DateUtils.getZuluTimeZone(), (String)g.get(string2.toLowerCase())));
                }
            }
            catch (IllegalArgumentException illegalArgumentException) {
                throw DateTimeSelector.a(illegalArgumentException);
            }
        }
        catch (DateUtils.InvalidPatternException invalidPatternException) {
            Object object;
            String string3;
            Syntax.SyntaxErrorHandler syntaxErrorHandler2;
            String string4 = ExceptionUtils.getMessage((Throwable)invalidPatternException);
            try {
                syntaxErrorHandler2 = syntaxErrorHandler;
                string3 = string2;
                object = string4.isEmpty() ? "" : " " + string4;
            }
            catch (DateUtils.InvalidPatternException invalidPatternException2) {
                throw DateTimeSelector.a((Exception)((Object)invalidPatternException2));
            }
            String string5 = syntaxErrorHandler2.handleBadVariable(string3 + h[0] + (String)object);
            try {
                if (bl2) {
                    throw new IllegalArgumentException(string5);
                }
            }
            catch (DateUtils.InvalidPatternException invalidPatternException3) {
                throw DateTimeSelector.a((Exception)((Object)invalidPatternException3));
            }
            return NOT_PRESENT;
        }
        if (string2.contains(".")) {
            int n2 = string2.indexOf(46);
            String string6 = string2.substring(0, n2);
            TimeZone timeZone = DateUtils.getTimeZone((String)string6);
            if (timeZone != null) {
                return new ExpandVariables.Selector.Selection(DateUtils.getFormattedString((Date)date, (TimeZone)timeZone, (String)this.a(string2.substring(n2 + 1))));
            }
            return new ExpandVariables.Selector.Selection(DateUtils.getFormattedString((Date)date, (TimeZone)DateUtils.getZuluTimeZone(), (String)this.a(string2)));
        }
        return new ExpandVariables.Selector.Selection(DateUtils.getFormattedString((Date)date, (TimeZone)DateUtils.getZuluTimeZone(), (String)this.a(string2)));
    }

    @Override
    public Class<Date> getContextObjectClass() {
        return Date.class;
    }

    String a(String string) {
        try {
            if (g.keySet().contains(string.toLowerCase())) {
                return g.get(string.toLowerCase());
            }
        }
        catch (IllegalArgumentException illegalArgumentException) {
            throw DateTimeSelector.a(illegalArgumentException);
        }
        return string;
    }

    /*
     * Unable to fully structure code
     */
    static {
        block10: {
            block9: {
                var5 = new String[13];
                var3_1 = 0;
                var2_2 = "6\u0011,\u0004R\u00065b\u0012c\u0002\u001b\u000f18\u0007e\u0012 \u0019\u001c\u0006'\u0006{\u001e/\u001a\u001b\u0011\u0007w\u0004 \u0002\u001b\u000f1\u0006{\u001e/\u001a\u001b\u0011\u0007\u007f\u0004,NDRe\u0007d\u0011 GCPg\u0007d\u0011 GCPg\u0007e\u0012 \u0019\u001c\u0006'\u0006d\u0011 NGR\u0007\u007f\u0004,NDRe";
                var4_3 = "6\u0011,\u0004R\u00065b\u0012c\u0002\u001b\u000f18\u0007e\u0012 \u0019\u001c\u0006'\u0006{\u001e/\u001a\u001b\u0011\u0007w\u0004 \u0002\u001b\u000f1\u0006{\u001e/\u001a\u001b\u0011\u0007\u007f\u0004,NDRe\u0007d\u0011 GCPg\u0007d\u0011 GCPg\u0007e\u0012 \u0019\u001c\u0006'\u0006d\u0011 NGR\u0007\u007f\u0004,NDRe".length();
                var1_4 = 15;
                var0_5 = -1;
lbl7:
                // 2 sources

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

                while (true) {
                    var5[var3_1++] = DateTimeSelector.a(v0, DateTimeSelector.b(v2));
                    if ((var0_5 += var1_4) < var4_3) {
                        var1_4 = var2_2.charAt(var0_5);
                        ** continue;
                    }
                    var2_2 = "z\t-\u000f\u0016\u0002<\u0006i\u001c-CJ_";
                    var4_3 = "z\t-\u000f\u0016\u0002<\u0006i\u001c-CJ_".length();
                    var1_4 = 7;
                    var0_5 = -1;
lbl22:
                    // 2 sources

                    while (true) {
                        v0 = 7;
                        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++] = DateTimeSelector.a(v0, DateTimeSelector.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;
            }
        }
        DateTimeSelector.h = var5;
        DateTimeSelector.d = DateTimeSelector.h[6];
        DateTimeSelector.e = DateTimeSelector.h[12];
        DateTimeSelector.c = DateTimeSelector.h[5];
        DateTimeSelector.b = DateTimeSelector.h[8];
        DateTimeSelector.a = DateTimeSelector.h[2];
        DateTimeSelector.f = DateTimeSelector.h[3];
        var0_6 = DateTimeSelector.h;
        DateTimeSelector.g = CollectionUtils.mapBuilder().put((Object)var0_6[10], (Object)DateUtils.ISO8601_PATTERN).put((Object)var0_6[7], (Object)DateUtils.RFC1123_DEFAULT_PATTERN).put((Object)var0_6[9], (Object)DateUtils.RFC850_DEFAULT_PATTERN).put((Object)var0_6[11], (Object)DateUtils.ASCTIME_DEFAULT_PATTERN).unmodifiableMap();
    }

    private static Exception a(Exception exception) {
        return exception;
    }

    private static char[] b(String string) {
        char[] cArray = string.toCharArray();
        if (cArray.length < 2) {
            cArray = cArray;
            cArray[0] = (char)(cArray[0] ^ 0x5E);
        }
        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 -> 28;
                    case 1 -> 125;
                    case 2 -> 73;
                    case 3 -> 124;
                    case 4 -> 120;
                    case 5 -> 104;
                    default -> 94;
                })));
                ++n3;
                n4 = n4;
            } while (n4 > n3);
        }
        return new String(cArray2).intern();
    }
}

