/*
 * Copyright 2012 Red Hat, Inc. and/or its affiliates.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.drools.examples.carinsurance.cep;
    dialect "java"

import org.drools.examples.carinsurance.domain.Car;
import org.drools.examples.carinsurance.domain.CarType;
import org.drools.examples.carinsurance.domain.Driver;
import org.drools.examples.carinsurance.domain.policy.Coverage;
import org.drools.examples.carinsurance.domain.policy.CoverageType;
import org.drools.examples.carinsurance.domain.policy.Policy;
import org.drools.examples.carinsurance.domain.request.CoverageRequest;
import org.drools.examples.carinsurance.domain.request.PolicyRequest;

// ############################################################################
// PolicyRequest fraud
// ############################################################################

declare PolicyRequest
    @role(event)
end

rule "lyingAboutAge" no-loop
    when
        $rejectedPolicyRequest : PolicyRequest(
            automaticallyRejected == true,
            $fullName : owner.fullName,
            $age : owner.age
        )
        $flaggedPolicyRequest : PolicyRequest(
            this after[1s, 30s] $rejectedPolicyRequest,
            automaticallyRejected == false,
            owner.fullName == $fullName,
            owner.age != $age
        )
    then
        $flaggedPolicyRequest.setRequiresManualApproval(true);
        $flaggedPolicyRequest.addFlaggedMessage("A driver with the same name (" + $fullName + ") but a different age ("
            + $age + ") recently filed a rejected request.");
end
