/*
 * Copyright 2010 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.troubleticket

import org.drools.examples.troubleticket.Customer;
import org.drools.examples.troubleticket.Ticket;

rule "New Ticket"
    salience 10
    when
        customer : Customer( )
        ticket : Ticket( customer == customer, status == "New" )
    then
        System.out.println( "New : " + ticket );
end
 
rule "Silver Priority"
    duration 3000
    when
        customer : Customer( subscription == "Silver" )
        ticket : Ticket( customer == customer, status == "New" )
    then
        modify( ticket ) { setStatus( "Escalate" ) };
end

rule "Gold Priority"
    duration 1000
    when
        customer : Customer( subscription == "Gold" )
        ticket : Ticket( customer == customer, status == "New" )
    then
        modify( ticket ) { setStatus( "Escalate" ) };
end

rule "Platinum Priority"
    when
        customer : Customer( subscription == "Platinum" )
        ticket : Ticket( customer == customer, status == "New" )
    then;
        modify( ticket ) { setStatus( "Escalate" ) };
end

rule "Escalate"
    when
        customer : Customer( )
        ticket : Ticket( customer == customer, status == "Escalate" )
    then
        sendEscalationEmail( customer, ticket );
end

rule "Done"
    when
        customer : Customer( )
        ticket : Ticket( customer == customer, status == "Done" )
    then
        System.out.println( "Done : " + ticket );
end

function void sendEscalationEmail( Customer customer, Ticket ticket ) {
    System.out.println( "Email : " + ticket );
}
