/*
 * Copyright 2011 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.traits

declare Person

    name    : String       = "john"     @key

    age     : int          = 18

    weight  : Double       = 75.4

end


declare Student extends Person

    school  : String
end


declare Worker extends Person

    wage    : int
end


rule "Zero"
when
then
    insert( new Person() );
end


rule "Students and Workers"
no-loop
when
    $p : Person( $name : name, $age : age < 25, $weight : weight )
then
    delete( $p );
    insert( new Student( $name, $age, $weight, "SomeSchool" ) );
    insert( new Worker( $name, $age, $weight, 1200 ) );
end


rule "Welcome"
salience 10
when
    $s : Student( $school : school, $name : name )
then
    System.out.println( "Dear "+ $name + ", welcome to " + $school );
end

rule "Hard toil"
salience 5
when
    $w : Worker( $name : name, $weight : weight, $wage : wage )
then
    System.out.println( "Work harder, " + $name );

    $w.setWage( $wage + 100 );
    $w.setWeight( $weight - 10 );

    //update( $w );
end


/*
declare StudentWorker extends Person // Sudent, Worker
    ...
end
*/