/*
 * Decompiled with CFR 0.152.
 * 
 * Could not load the following classes:
 *  com.l7tech.gateway.common.audit.AssertionMessages
 *  com.l7tech.gateway.common.audit.AuditDetailMessage
 *  com.l7tech.policy.assertion.AssertionStatus
 *  com.l7tech.policy.assertion.PolicyAssertionException
 *  com.l7tech.policy.assertion.TimeOfDay
 *  com.l7tech.policy.assertion.TimeRange
 */
package com.l7tech.server.policy.assertion;

import com.l7tech.gateway.common.audit.AssertionMessages;
import com.l7tech.gateway.common.audit.AuditDetailMessage;
import com.l7tech.policy.assertion.AssertionStatus;
import com.l7tech.policy.assertion.PolicyAssertionException;
import com.l7tech.policy.assertion.TimeOfDay;
import com.l7tech.policy.assertion.TimeRange;
import com.l7tech.server.message.PolicyEnforcementContext;
import com.l7tech.server.policy.assertion.AbstractServerAssertion;
import com.l7tech.server.policy.assertion.ServerAssertion;
import java.io.IOException;
import java.util.Calendar;
import java.util.TimeZone;

public class ServerTimeRange
extends AbstractServerAssertion<TimeRange>
implements ServerAssertion<TimeRange> {
    private static final TimeOfDay d;
    private static final String e;

    public ServerTimeRange(TimeRange timeRange) {
        super(timeRange);
    }

    @Override
    public AssertionStatus checkRequest(PolicyEnforcementContext policyEnforcementContext) throws IOException, PolicyAssertionException {
        block14: {
            Calendar calendar;
            block13: {
                block12: {
                    try {
                        try {
                            if (((TimeRange)this.assertion).isControlDay() || ((TimeRange)this.assertion).isControlTime()) break block12;
                        }
                        catch (IOException iOException) {
                            throw ServerTimeRange.a(iOException);
                        }
                        this.logAndAudit((AuditDetailMessage)AssertionMessages.TIME_RANGE_NOTHING_TO_CHECK);
                        return AssertionStatus.NONE;
                    }
                    catch (IOException iOException) {
                        throw ServerTimeRange.a(iOException);
                    }
                }
                calendar = Calendar.getInstance(TimeZone.getTimeZone(e));
                try {
                    try {
                        if (!((TimeRange)this.assertion).isControlDay() || this.a(calendar)) break block13;
                    }
                    catch (IOException iOException) {
                        throw ServerTimeRange.a(iOException);
                    }
                    this.logAndAudit((AuditDetailMessage)AssertionMessages.TIME_RANGE_DOW_OUTSIDE_RANGE);
                    return AssertionStatus.FAILED;
                }
                catch (IOException iOException) {
                    throw ServerTimeRange.a(iOException);
                }
            }
            try {
                try {
                    if (!((TimeRange)this.assertion).isControlTime() || this.b(calendar)) break block14;
                }
                catch (IOException iOException) {
                    throw ServerTimeRange.a(iOException);
                }
                this.logAndAudit((AuditDetailMessage)AssertionMessages.TIME_RANGE_TOD_OUTSIDE_RANGE);
                return AssertionStatus.FAILED;
            }
            catch (IOException iOException) {
                throw ServerTimeRange.a(iOException);
            }
        }
        this.logAndAudit((AuditDetailMessage)AssertionMessages.TIME_RAGNE_WITHIN_RANGE);
        return AssertionStatus.NONE;
    }

    private boolean a(Calendar calendar) {
        int n2 = calendar.get(7);
        if (((TimeRange)this.assertion).getEndDayOfWeek() < ((TimeRange)this.assertion).getStartDayOfWeek()) {
            if (n2 >= ((TimeRange)this.assertion).getStartDayOfWeek() && n2 <= 7) {
                return true;
            }
            return n2 <= ((TimeRange)this.assertion).getEndDayOfWeek();
        }
        return n2 >= ((TimeRange)this.assertion).getStartDayOfWeek() && n2 <= ((TimeRange)this.assertion).getEndDayOfWeek();
    }

    private boolean b(Calendar calendar) {
        TimeOfDay timeOfDay;
        TimeOfDay timeOfDay2 = new TimeOfDay(calendar.get(11), calendar.get(12), calendar.get(13));
        TimeOfDay timeOfDay3 = ((TimeRange)this.assertion).getTimeRange().getFrom();
        if (timeOfDay3.compareTo((Object)(timeOfDay = ((TimeRange)this.assertion).getTimeRange().getTo())) > 0) {
            if (timeOfDay2.compareTo((Object)timeOfDay3) >= 0 && timeOfDay2.compareTo((Object)d) <= 0) {
                return true;
            }
            return timeOfDay2.compareTo((Object)timeOfDay) <= 0;
        }
        return timeOfDay2.compareTo((Object)timeOfDay) <= 0 && timeOfDay2.compareTo((Object)timeOfDay3) >= 0;
    }

    /*
     * Enabled aggressive block sorting
     */
    static {
        e = ServerTimeRange.b(127, ServerTimeRange.a("\u0005I\u0004"));
        d = new TimeOfDay(23, 59, 59);
    }

    private static IOException a(IOException iOException) {
        return iOException;
    }

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

    /*
     * Handled impossible loop by duplicating code
     * Enabled aggressive block sorting
     */
    private static String b(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 -> 61;
                    case 1 -> 123;
                    case 2 -> 47;
                    case 3 -> 70;
                    case 4 -> 38;
                    case 5 -> 78;
                    default -> 100;
                })));
                ++n3;
                n4 = n4;
            } while (n4 > n3);
        }
        return new String(cArray2).intern();
    }
}

