#ifndef _WB_OVERVIEW_PHYSICAL_H_
#define _WB_OVERVIEW_PHYSICAL_H_

#include "wb_overview.h"

namespace wb {
  class PhysicalOverviewBE;
  
  namespace internal {
    
    class PhysicalSchemataNode : public OverviewBE::ContainerNode
    {
      workbench_physical_ModelRef model;

      virtual bool add_object(WBContext *wb);
      virtual void delete_object(WBContext *wb);
      virtual void refresh_children();

    public:
      PhysicalSchemataNode(workbench_physical_ModelRef model);
    };


    class SQLScriptsNode : public OverviewBE::ContainerNode 
    {
    private:
      PhysicalOverviewBE *_owner;
      std::string id;
      workbench_physical_ModelRef _model;

      bool add_new(WBContext *wb);
      
    public:
      SQLScriptsNode(workbench_physical_ModelRef model, PhysicalOverviewBE *owner);

      virtual void refresh_children();

      virtual int get_popup_menu_items(WBContext *wb, bec::MenuItemList &items);
      virtual std::string get_unique_id()
      { 
        return id;
      }
    };


    class NotesNode : public OverviewBE::ContainerNode 
    {
    private:
      PhysicalOverviewBE *_owner;
      std::string id;
      workbench_physical_ModelRef _model;

      bool add_new(WBContext *wb);
      
    public:
      NotesNode(workbench_physical_ModelRef model, PhysicalOverviewBE *owner);

      virtual void refresh_children();

      virtual int get_popup_menu_items(WBContext *wb, bec::MenuItemList &items);
      virtual std::string get_unique_id()
      { 
        return id;
      }
    };
  };



  //
  // Node Layout:
  //
  // -root: ORoot  (model)   (stable nodeid)
  //   -diagrams: ODivision  (stable noteid)  <RefreshChildren>
  //     -[diagram nodes]: OItem   <RefreshNode>
  //   -schemata: ODivision     (stable nodeid) <RefreshChildren>
  //     -[schema]: OGroup   (kind of stable by oid*)  <RefreshNode>
  //       -table: OSection (stable for parent)   <RefreshChildren>
  //         -[table nodes]: OItem      <RefreshNode>
  //       -view: OSection (stable for parent)    <RefreshChildren>
  //         -[view nodes]: OItem       <RefreshNode>
  //       -routine: OSection (stable for parent) <RefreshChildren>
  //         -[routine nodes]: OItem    <RefreshNode>
  //       -routineGroup: OSection (stable for parent)<RefreshChildren>
  //         -[routineGroup nodes]: OItem <RefreshNode>
  //   -privileges: ODivision  (stable nodeid)  <RefreshChildren>
  //     -users: OSection (stable nodeid)
  //       -[users]: OItem
  //     -roles: OSection (stable nodeid) <RefreshChildren>
  //       -[roles]: OItem
  //   -scripts: ODivision (stable nodeid)  <RefreshChildren>
  //     -[scripts] OItem
  //   -notes: ODivision (stable nodeid)  <RefreshChildren>
  //     -[notes] OItem
  //
  // Nodes marked <RefreshChildren> must have their contents refreshable when
  // Refresh message is received by the frontend. Arguments are paths.
  class MYSQLWBBACKEND_PUBLIC_FUNC PhysicalOverviewBE : public OverviewBE
  {
    workbench_physical_ModelRef _model;

  public: // backend internal
    virtual std::string identifier() const;
    virtual std::string get_title();
    
    virtual std::string get_form_context_name() const;

    virtual void send_refresh_diagram(const model_DiagramRef &view);
    void send_refresh_users();
    void send_refresh_roles();
    void send_refresh_scripts();
    void send_refresh_notes();
    void send_refresh_schema_list();
    void send_refresh_for_schema(const db_SchemaRef &schema, bool refresh_object_itself);
    void send_refresh_for_schema_object(const GrtObjectRef &object, bool refresh_object_itself);

    void set_model(workbench_physical_ModelRef model);

  public:
    PhysicalOverviewBE(WBContext *wb);

    virtual model_ModelRef get_model();

    virtual std::string get_node_drag_type(const bec::NodeId &node);
    virtual bool should_accept_file_drop_to_node(const bec::NodeId &node, const std::string &path);
    virtual void add_file_to_node(const bec::NodeId &node, const std::string &path);
    virtual bool get_file_data_for_node(const bec::NodeId &node, char *&data, size_t &length);
    virtual std::string get_file_for_node(const bec::NodeId &node);

    virtual void refresh_node(const bec::NodeId &node, bool children);
  };
};

#endif /* _WB_OVERVIEW_PHYSICAL_H_ */
