package au.gov.amsa.detection.behaviour;

import au.gov.amsa.detection.model.Contact;
import au.gov.amsa.detection.model.Contact.Behaviour;
import au.gov.amsa.detection.model.Contact.Events.Create;
import au.gov.amsa.detection.model.Contact.Events.Send;

public class ContactBehaviour implements Behaviour {

    private final Contact contact;
    private final ContactSender sender;

    public ContactBehaviour(Contact contact, ContactSender sender) {
        this.contact = contact;
        this.sender = sender;
    }

    @Override
    public void onEntryCreated(Create event) {
        // TODO Auto-generated method stub

    }

    @Override
    public void onEntrySent(Send event) {
        // TODO Auto-generated method stub

    }

}

@@ -35,16 +35,58 @@
 viour;%0A%0A
+import au.gov.amsa.detection.ArbitraryId;%0A
 import a
@@ -288,16 +288,214 @@
 ts.Send;
+%0Aimport au.gov.amsa.detection.model.Craft;%0Aimport au.gov.amsa.detection.model.DetectionMessage;%0Aimport au.gov.amsa.detection.model.DetectionRule;%0Aimport au.gov.amsa.detection.model.MessageRecipient;
 %0A%0Apublic
@@ -568,23 +568,20 @@
 Contact 
-contact
+self
 ;%0A    pr
@@ -651,23 +651,20 @@
 Contact 
-contact
+self
 , Contac
@@ -698,25 +698,19 @@
 his.
-contact = contact
+self = self
 ;%0A  
@@ -817,150 +817,706 @@
     
-// TODO Auto-generated method stub%0A%0A    %7D%0A%0A    @Override%0A    public void onEntrySent(Send event) %7B%0A        // TODO Auto-generated method stub%0A
+self.setId(ArbitraryId.next());%0A        self.setEmail(event.getEmail());%0A        MessageRecipient r = MessageRecipient.create(ArbitraryId.next());%0A        r.setStartTime(event.getStartTime());%0A        r.setEndTime(event.getEndTime());%0A        r.relateAcrossR16(DetectionRule.find(event.getDetectionRuleID()).get());%0A        r.setState(MessageRecipient.State.CREATED);%0A        r.relateAcrossR14(self);%0A        r.persist();%0A    %7D%0A%0A    @Override%0A    public void onEntrySent(Send event) %7B%0A        DetectionMessage m = DetectionMessage.find(event.getDetectionMessageID()).get();%0A        Craft craft = m.getDetection_R11().getCraft_R6();%0A        sender.send(self.getEmail(), m.getSubject(), m.getBody());
 %0A   

add contact behaviour