#ifndef Interaction_h_DEFINED
#define Interaction_h_DEFINED

#include "../const.h"

#ifdef AIBO_YES
#include "def.h"
#include "Init_per_para.h"
#include <OPENR/OObject.h>
#include <OPENR/OSubject.h>
#include <OPENR/OObserver.h>
#include <stdlib.h>
#include "../FaceExpr/Emotion.h"


// Defining new type 'state'
enum state {AIBO_NEUTRAL, AIBO_JOYFUL, AIBO_SAD, AIBO_ANGRY};

// Defining new type 'input'
enum input {USER_NEUTRAL, USER_JOYFUL, USER_SAD, USER_SURPRISED,
            USER_ANGRY, USER_FEARFUL, USER_DISGUSTED};

struct Personality {

       state initial_state;
       state current_state;
       float nice_interaction_points;
       float sad_interaction_points;
       float bad_interaction_points;
       float*** transition_prob;     // probabilistic transition probabilities

       Personality() {
          initial_state = current_state = AIBO_NEUTRAL;
          nice_interaction_points = sad_interaction_points = bad_interaction_points = 0.0;

          transition_prob = (float***) calloc(STATE_NUM, sizeof(float**));
          for (int i = 0; i < STATE_NUM; i++) {
              transition_prob[i] = (float**) calloc(EM_NUM + 1, sizeof(float*));
              for (int j = 0; j < EM_NUM + 1; j++) {
                  transition_prob[i][j] = (float*) calloc(STATE_NUM, sizeof(float));
              }
          }

                     	
       }


};


enum States {
     IDLE,
     START,
     WAITING
};

class Interaction : public OObject {
public:
    Interaction();
    virtual ~Interaction() {}

    OSubject*    subject[numOfSubject];
    OObserver*   observer[numOfObserver];

    Personality per;
    Init_per_para per_parameters;

    virtual OStatus DoInit   (const OSystemEvent& event);
    virtual OStatus DoStart  (const OSystemEvent& event);
    virtual OStatus DoStop   (const OSystemEvent& event);
    virtual OStatus DoDestroy(const OSystemEvent& event);

    void ReadyCommand(const OReadyEvent& event);
    void Interact(const ONotifyEvent& event);
    void NotifyResult(const ONotifyEvent& event);



private:   
    
    bool InitPersonality();
    void UpdatePersonality(Emotion& emotion);
    void UpdatePersonalityImitating();
    void UpdatePersonalityCompensating();
    void ExecuteMotion(int command);
    bool CheckProb();
    void FreePersonality();


    States              interactionState;

};

#endif


#endif // Interaction_h_DEFINED

