package au.gov.amsa.detection.behaviour;

import au.gov.amsa.detection.ArbitraryId;
import au.gov.amsa.detection.model.Context;
import au.gov.amsa.detection.model.DetectedCraft;
import au.gov.amsa.detection.model.DetectedCraft.Behaviour;
import au.gov.amsa.detection.model.DetectedCraft.Events.Create;
import au.gov.amsa.detection.model.DetectedCraft.Events.Send;
import au.gov.amsa.detection.model.DetectionRule;
import au.gov.amsa.detection.model.MessageRecipient;

public class DetectedCraftBehaviour implements Behaviour {

    private final DetectedCraft self;

    public DetectedCraftBehaviour(DetectedCraft self) {
        this.self = self;
    }

    @Override
    public void onEntryCreated(Create event) {
        self.setId(ArbitraryId.next());
        MessageRecipient r = MessageRecipient.create(ArbitraryId.next());
        r.setDetectionRule_R16(DetectionRule.find(event.getDetectionRuleID()).get());
        r.setState(MessageRecipient.State.CREATED);
        self.relateAcrossR14(r);
        r.persist(Context.em());
    }

    @Override
    public void onEntrySent(Send event) {
        System.out.println("SENDING to DETECTED CRAFT");
    }

}

@@ -35,16 +35,74 @@
 viour;%0A%0A
+import org.slf4j.Logger;%0Aimport org.slf4j.LoggerFactory;%0A%0A
 import a
@@ -135,16 +135,16 @@
 raryId;%0A
-
 import a
@@ -179,16 +179,58 @@
 ontext;%0A
+import au.gov.amsa.detection.model.Craft;%0A
 import a
@@ -457,16 +457,69 @@
 s.Send;%0A
+import au.gov.amsa.detection.model.DetectionMessage;%0A
 import a
@@ -713,16 +713,110 @@
  self;%0A%0A
+    private static final Logger log = LoggerFactory.getLogger(DetectedCraftBehaviour.class);%0A%0A
     publ
@@ -1350,54 +1350,278 @@
     
-System.out.println(%22SENDING to DETECTED CRAFT%22
+DetectionMessage m = DetectionMessage.find(event.getDetectionMessageID()).get();%0A        Craft craft = m.getDetection_R11().getCraft_R6();%0A        log.info(String.format(%22SENDING to DETECTED CRAFT %25s %25s%22, craft.getIdentifierType(),%0A                craft.getIdentifier())
 );%0A 

send to detected craft