
/**
 * @license
 * Copyright 2018 The FOAM Authors. All Rights Reserved.
 * http://www.apache.org/licenses/LICENSE-2.0
 */


foam.CLASS({
    package: 'foam.nanos.logger',
    name: 'NotificationLogger',
    extends: 'foam.nanos.logger.ProxyLogger',

    javaImports: [
      'foam.dao.DAO',
      'foam.core.X'
  ],

    requires: [
      'foam.nanos.logger.LogLevel',
      'foam.nanos.notification.Notification',
    ],

    properties: [
      {
        class: 'Int',
        name: 'errorLevelThreshhold',
        value: 2,
      },
      {
        class: 'Enum',
        of: 'foam.nanos.logger.LogLevel',
        name: 'lastLogLevel',
        factory: function() { return foam.nanos.logger.LogLevel.INFO; }
      }
    ],

    methods: [
      {
        name: 'generateNotificationEvent',
        // args: [
        //   {
        //     name: 'currentThreshhold',
        //     javaType: 'Enum'
        //   },
        //   {
        //     name: 'updateLastLogLevel',
        //     javaType: 'Boolean'
        //   },
        //   {
        //     name: 'args',
        //     javaType: 'Object...'
        //   },
        // ],
//        javaReturns: 'void',
        javaCode: `

            X x = getX();
            foam.nanos.notification.Notification s = new foam.nanos.notification.Notification();
            s.setUserId(9);
            s.setEmailIsEnabled(true);
        //    s.setGroupId("NOC");
            s.setEmailName("notification-logger-error");
            s.setBody("A notification email was triggered from the nanopay notification logger.");
            ((DAO) x.get("notificationDAO")).put_(x,s) ;
        `
      },
      {
        name: 'info',
        args: [
          {
            name: 'args',
            javaType: 'Object...'
          }
        ],
        javaReturns: 'void',
        javaCode: `
        System.err.print(args);
        getDelegate().info(args);          
        if (LogLevel.INFO.getOrdinal() >= getErrorLevelThreshhold() ) {
          System.err.print("generate notification event");
          generateNotificationEvent();
        }
        `
    },



    ]
  });

@@ -792,383 +792,8 @@
 t',%0A
-        // args: %5B%0A        //   %7B%0A        //     name: 'currentThreshhold',%0A        //     javaType: 'Enum'%0A        //   %7D,%0A        //   %7B%0A        //     name: 'updateLastLogLevel',%0A        //     javaType: 'Boolean'%0A        //   %7D,%0A        //   %7B%0A        //     name: 'args',%0A        //     javaType: 'Object...'%0A        //   %7D,%0A        // %5D,%0A//        javaReturns: 'void',%0A
     
@@ -808,17 +808,16 @@
 Code: %60%0A
-%0A
         
@@ -938,24 +938,27 @@
 %0A           
+ //
  s.setUserId
@@ -962,16 +962,49 @@
 rId(9);%0A
+            s.setGroupId(%22NOC%22);%0A
         
@@ -1038,43 +1038,8 @@
 e);%0A
-        //    s.setGroupId(%22NOC%22);%0A
     
@@ -1201,16 +1201,54 @@
         
+ if (x.get(%22notificationDAO%22) != null)
  ((DAO) 
@@ -1304,30 +1304,26 @@
      %7D,%0A    
-  %7B%0A  
+%7B%0A
       name: 
@@ -1336,18 +1336,16 @@
 ,%0A      
- 
- 
 args: %5B%0A
@@ -1348,30 +1348,26 @@
 : %5B%0A        
-  %7B%0A  
+%7B%0A
           na
@@ -1384,26 +1384,24 @@
 ,%0A          
-  
 javaType: 'O
@@ -1414,30 +1414,26 @@
 ..'%0A        
-  %7D%0A  
+%7D%0A
       %5D,%0A   
@@ -1431,26 +1431,24 @@
    %5D,%0A      
-  
 javaReturns:
@@ -1454,34 +1454,32 @@
 : 'void',%0A      
-  
 javaCode: %60%0A    
@@ -1484,36 +1484,175 @@
     
-  System.err.print(args);%0A  
+if (LogLevel.INFO.getOrdinal() %3E= getErrorLevelThreshhold() ) %7B%0A        generateNotificationEvent();%0A        System.err.print(%22info notification email sent%22);%0A      %7D%0A
     
@@ -1689,20 +1689,183 @@
        %0A
+%0A
     
+  %60%0A  %7D,%0A  %7B%0A    name: 'warning',%0A    args: %5B%0A      %7B%0A        name: 'args',%0A        javaType: 'Object...'%0A      %7D%0A    %5D,%0A    javaReturns: 'void',%0A    javaCode: %60%0A
     if (
@@ -1865,36 +1865,39 @@
    if (LogLevel.
-INFO
+WARNING
 .getOrdinal() %3E=
@@ -1927,24 +1927,55 @@
 d() ) %7B%0A    
+  generateNotificationEvent();%0A
       System
@@ -1986,24 +1986,23 @@
 .print(%22
-generate
+warning
  notific
@@ -2012,73 +2012,416 @@
 on e
-vent%22);
+mail sent%22);      
 %0A    
+%7D%0A
     
-  generateNotificationEvent();%0A        %7D%0A
+getDelegate().warning(args);          %0A    %60%0A%7D,%0A%7B%0A  name: 'error',%0A  args: %5B%0A    %7B%0A      name: 'args',%0A      javaType: 'Object...'%0A    %7D%0A  %5D,%0A  javaReturns: 'void',%0A  javaCode: %60%0A  if (LogLevel.ERROR.getOrdinal() %3E= getErrorLevelThreshhold() ) %7B%0A    generateNotificationEvent();%0A    System.err.print(%22error notification email sent%22);    %0A  %7D%0A  getDelegate().error(args); 
         
 %60%0A  
@@ -2416,22 +2416,25 @@
         
-%60
+ 
 %0A  
+%0A
   
+%60%0A
 %7D,%0A%0A%0A%0A  

add warning and error methods