/*
 * Copyright 2011 JBoss Inc
 *
 * 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
    @Traitable

    name    : String       = "john"     @key

    age     : int          = 18

    weight  : Double       = 75.4

end


declare trait IPerson

    name    : String

    age     : int

    weight  : Double

end


declare trait IStudent extends IPerson

    school  : String
end


declare trait IWorker extends IPerson

    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
    IWorker w = don( $p, IWorker.class, true );
        w.setWage( 1200 );
    update( w );

    IStudent s = don( $p, IStudent.class, true );
        s.setSchool( "SomeSchool" );
    update( s );
end


rule "Working Students"
salience -10
when
    $s : IStudent( $school : school, $name : name,
                   this isA IWorker, $wage : fields[ "wage" ] )
then
    System.out.println( $name + " : I have " + $wage + " to pay the fees at " + $school );
end
















