/**
 * @license
 * Visual Blocks Editor
 *
 * Copyright 2012 Google Inc.
 * https://developers.google.com/blockly/
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

/**
 * @fileoverview Colour blocks for Blockly.
 * @author fraser@google.com (Neil Fraser)
 */
'use strict';

goog.provide('Blockly.Blocks.visionkit');

goog.require('Blockly.Blocks');


/**
 * Common HSV hue for all blocks in this category.
 */
Blockly.Blocks.visionkit.HUE = "#2c4fc9";

Blockly.Blocks['visionkit_setup'] = {
  /**
   * Block for log setup.
   * @this Blockly.Block
   */
  init: function() {
    this.setColour(Blockly.Blocks.visionkit.HUE);   
        this.appendDummyInput()
        // .appendField(new Blockly.FieldImage("./../blockly/media/google_aiy_vision_kit_setup_header.png", 140, 60, "0"));
        .appendField(new Blockly.FieldImage("./blockly/media/google_aiy_vision_kit_setup.png", 140, 60, "0"));//staging
    this.appendDummyInput()
        .appendField(Blockly.Msg.VISIONKIT_SETUP);
    // this.setInputsInline(false);
    // this.setOutput(true);
    // this.setPreviousStatement(true);
    // this.setNextStatement(true);
  },
};

Blockly.Blocks['visionkit_demo'] = {
  /**
   * Block for log setup.
   * @this Blockly.Block
   */
  init: function() {
    this.setColour(Blockly.Blocks.visionkit.HUE); 
            this.appendDummyInput()
        // .appendField(new Blockly.FieldImage("./../blockly/media/google_aiy_vision_kit_setup_header.png", 140, 60, "0"));
        .appendField(new Blockly.FieldImage("./blockly/media/google_aiy_vision_joy_demo.png", 140, 60, "0"));//staging
    this.appendDummyInput()
        .appendField(Blockly.Msg.VISIONKIT_JOY_DETECT);
    this.appendDummyInput()
        .appendField(Blockly.Msg.VISIONKIT_CLOUDEVENT_API)
        .appendField(new Blockly.FieldTextInput("yourCloudEventAPI"),"API")
    // this.setInputsInline(false);
    // this.setOutput(true);
    // this.setPreviousStatement(true);
    // this.setNextStatement(true);
  },
};


/*
 * vision kit
 * import block from
 */

Blockly.Blocks['visionkit_import'] = {
     /**
   * Block for import.
   * @this Blockly.Block
   */
  init: function() {
    this.setColour(Blockly.Blocks.visionkit.HUE);   
    this.appendValueInput("IMPORT")
        .appendField(Blockly.Msg.VISIONKIT_IMPORT)
        .appendField(new Blockly.FieldDropdown([
            ["AIY.Vision.Inference","aiy.vision.inference"],
            ["AIY.Vision.Models","aiy.vision.models"],
            ["AIY.Vision.Annotator","aiy.vision.annotator"]
            ]), "FROM")
    // this.setInputsInline(false);
    // this.setOutput(true);
    this.setPreviousStatement(true);
    this.setNextStatement(true);
  },
};

/*
 * vision kit
 * import block annotator
 */

Blockly.Blocks['visionkit_import_annotator'] = {
     /**
   * Block for import.
   * @this Blockly.Block
   */
  init: function() {
    this.setColour(Blockly.Blocks.visionkit.HUE);   
    this.appendDummyInput()
        .appendField(Blockly.Msg.VISIONKIT_IMPORT_ANNOTATOR)
        .appendField(new Blockly.FieldDropdown([
            ["Annotator","Annotator"]
            ]), "IMPORT")
    // this.setInputsInline(false);
    this.setOutput(true);
    // this.setPreviousStatement(true);
    // this.setNextStatement(true);
  },
};


/*
 * vision kit
 * import block models
 */

Blockly.Blocks['visionkit_import_models'] = {
     /**
   * Block for import.
   * @this Blockly.Block
   */
  init: function() {
    this.setColour(Blockly.Blocks.visionkit.HUE);   
    this.appendDummyInput()
        .appendField(Blockly.Msg.VISIONKIT_IMPORT_MODELS)
        .appendField(new Blockly.FieldDropdown([
            ["Face Detection","face_detection"]
            ]), "IMPORT")
    // this.setInputsInline(false);
    this.setOutput(true);
    // this.setPreviousStatement(true);
    // this.setNextStatement(true);
  },
};

/*
 * vision kit
 * import block inference
 */

Blockly.Blocks['visionkit_import_inference'] = {
     /**
   * Block for import.
   * @this Blockly.Block
   */
  init: function() {
    this.setColour(Blockly.Blocks.visionkit.HUE);   
    this.appendDummyInput()
        .appendField(Blockly.Msg.VISIONKIT_IMPORT_INFERENCE)
        .appendField(new Blockly.FieldDropdown([
            ["Camera Inference","CameraInference"]
            ]), "IMPORT")
    // this.setInputsInline(false);
    this.setOutput(true);
    // this.setPreviousStatement(true);
    // this.setNextStatement(true);
  },
};

/*
 * vision kit
 * camera inference block
 */

Blockly.Blocks['visionkit_cameraInference'] = {
     /**
   * Block for import.
   * @this Blockly.Block
   */
  init: function() {
    this.setColour(Blockly.Blocks.visionkit.HUE); 
    this.appendDummyInput()
        .appendField(Blockly.Msg.VISIONKIT_AIY_VISION_INFERENCE)
    this.appendDummyInput()
        .appendField(Blockly.Msg.VISIONKIT_CAMERA_INFERENCE)
        .appendField(new Blockly.FieldTextInput("inference"),"INFERENCE")
    this.appendDummyInput()
        .appendField(Blockly.Msg.VISIONKIT_USE_MODEL)
        .appendField(new Blockly.FieldDropdown([
            ["Face Detection","face_detection.model()"]
        ]), "USEMODEL")
    this.appendStatementInput("STACK")
        .appendField(Blockly.Msg.VISIONKIT_DO)
    // this.setInputsInline(false);
    // this.setOutput(true);
    this.setPreviousStatement(true);
    this.setNextStatement(true);
  },
};

/*
 * vision kit
 * run inference block
 */

Blockly.Blocks['visionkit_runInference'] = {
     /**
   * Block for import.
   * @this Blockly.Block
   */
  init: function() {
    this.setColour(Blockly.Blocks.visionkit.HUE); 
    this.appendValueInput("INPUT")
        .appendField(Blockly.Msg.VISIONKIT_RUN_INFERENCE)
    this.setInputsInline(true);
    this.setOutput(true);
    // this.setPreviousStatement(true);
    // this.setNextStatement(true);
  },
};

/*
 * vision kit
 * get inference block
 */
Blockly.Blocks['visionkit_GetInference'] = {
     /**
   * Block for import.
   * @this Blockly.Block
   */
  init: function() {
    this.setColour(Blockly.Blocks.visionkit.HUE); 
    this.appendDummyInput()
        .appendField(Blockly.Msg.VISIONKIT_GETINFERENCE)
        .appendField(new Blockly.FieldDropdown([
            ["Count","count"],
            ["Rate","rate"]
        ]),"INFERENCE")
    // this.setInputsInline(true);
    this.setOutput(true);
    // this.setPreviousStatement(true);
    // this.setNextStatement(true);
  },
};



/*
 * vision kit
 * get inference block
 */
Blockly.Blocks['visionkit_faceDetection_operation'] = {
     /**
   * Block for import.
   * @this Blockly.Block
   */
  init: function() {
    this.setColour(Blockly.Blocks.visionkit.HUE); 
    this.appendValueInput("INPUT")
        .appendField(Blockly.Msg.VISIONKIT_IMPORT)
        .appendField(new Blockly.FieldDropdown([
            ["Face Detection","face_detection"]
        ]),"MODEL")
        .appendField(Blockly.Msg.VISISONKIT_MODEL)
        .appendField(new Blockly.FieldDropdown([
            ["Get Faces","get_faces"]
        ]),"OPERATION")
    // this.setInputsInline(true);
    this.setOutput(true);
    // this.setPreviousStatement(true);
    // this.setNextStatement(true);
  },
};

/*
 * vision kit
 * get model block
 */
Blockly.Blocks['visionkit_model_get'] = {
     /**
   * Block for import.
   * @this Blockly.Block
   */
  init: function() {
    this.setColour(Blockly.Blocks.visionkit.HUE); 
    this.appendValueInput("INPUT")
        .appendField(Blockly.Msg.VISIONKIT_GETMODEL_MODEL)
        .appendField(new Blockly.FieldDropdown([
            ["Bounding Box","bounding_box"],
            ["Joy Score","joy_score"]
        ]),"MODEL")
        .appendField(Blockly.Msg.VISIONKIT_GETMODEL_OF)
    this.setInputsInline(true);
    this.setOutput(true);
    // this.setPreviousStatement(true);
    // this.setNextStatement(true);
  },
};

/*
 * vision kit
 * Use Annotator block
 */
Blockly.Blocks['visionkit_Use_Annotator'] = {
     /**
   * Block for import.
   * @this Blockly.Block
   */
  init: function() {
    this.setColour(Blockly.Blocks.visionkit.HUE); 
    this.appendDummyInput()
        .appendField(Blockly.Msg.VISIONKIT_ANNOTATOR)
        .appendField(new Blockly.FieldTextInput("camera"),"ANNOTATOR")
        .appendField(Blockly.Msg.VISIONKIT_ANNOTATOR_SETTING)
        .appendField(new Blockly.FieldTextInput("320"),"X-DIMEN")
        .appendField(",")
        .appendField(new Blockly.FieldTextInput("240"),"Y-DIMEN")
    // this.setInputsInline(true);
    // this.setOutput(true);
    this.setPreviousStatement(true);
    this.setNextStatement(true);
  },
};

Blockly.Blocks['visionkit_Use_Annotator_output'] = {
     /**
   * Block for import.
   * @this Blockly.Block
   */
  init: function() {
    this.setColour(Blockly.Blocks.visionkit.HUE); 
    this.appendDummyInput()
        .appendField(Blockly.Msg.VISIONKIT_ANNOTATOR)
        .appendField(new Blockly.FieldTextInput("camera"),"ANNOTATOR")
        .appendField(Blockly.Msg.VISIONKIT_ANNOTATOR_SETTING)
        .appendField(new Blockly.FieldTextInput("320"),"X-DIMEN")
        .appendField(",")
        .appendField(new Blockly.FieldTextInput("240"),"Y-DIMEN")
    // this.setInputsInline(true);
    this.setOutput(true);
    // this.setPreviousStatement(true);
    // this.setNextStatement(true);
  },
};

/*
 * vision kit
 * Annotator clear/update block
 */
Blockly.Blocks['visionkit_Annotator_operation'] = {
     /**
   * Block for import.
   * @this Blockly.Block
   */
  init: function() {
    this.setColour(Blockly.Blocks.visionkit.HUE); 
    this.appendDummyInput()
        .appendField(Blockly.Msg.VISIONKIT_ANNOTATOR)
        .appendField(new Blockly.FieldDropdown([
            ["Clear","clear"],
            ["Update","update"]
        ]),"OPERATION")
    // this.setInputsInline(true);
    // this.setOutput(true);
    this.setPreviousStatement(true);
    this.setNextStatement(true);
  },
};


/*
 * vision kit
 * Annotator Bounding block
 */
Blockly.Blocks['visionkit_Annotator_Bounding'] = {
     /**
   * Block for import.
   * @this Blockly.Block
   */
  init: function() {
    this.setColour(Blockly.Blocks.visionkit.HUE); 
    this.appendDummyInput()
        .appendField(Blockly.Msg.VISIONKIT_ANNOTATOR_BOUNDING)
    this.appendValueInput("INPUT")
        .appendField(Blockly.Msg.VISIONKIT_ANNOTATOR_FILL)
        .appendField(new Blockly.FieldNumber("1"),"FILL")
    // this.setInputsInline(true);
    // this.setOutput(true);
    this.setPreviousStatement(true);
    this.setNextStatement(true);
  },
};

Blockly.Blocks['visionkit_myAssistant'] = {
    /**
   * Block for import.
   * @this Blockly.Block
   */
  init: function() {
    this.setColour(Blockly.Blocks.visionkit.HUE); 
    this.appendDummyInput()
        .appendField("MyAssistant")
    // this.setInputsInline(true);
    this.setOutput(true);
    // this.setPreviousStatement(true);
    // this.setNextStatement(true);
  },
}



/************************************
*           Simplify                *
*************************************/
Blockly.Blocks['visionkit_import_aiy'] = {
    /**
   * Block for import.
   * @this Blockly.Block
   */
  init: function() {
    this.setColour(Blockly.Blocks.visionkit.HUE); 
    this.appendDummyInput()
        .appendField("import AIY Vision Kit Modules")
    // this.appendValueInput("INPUT")
        // .appendField("faces")
    // this.setInputsInline(true);
    this.setPreviousStatement(true);
    this.setNextStatement(true);
  },
}

Blockly.Blocks['visionkit_avg_joy_score'] = {
  /**
   * Block for import.
   * @this Blockly.Block
   */
  init: function() {
    this.setColour(Blockly.Blocks.visionkit.HUE); 
    this.appendDummyInput()
        .appendField("Define Average Joy Score Demo")
    // this.appendValueInput("INPUT")
        // .appendField("faces")
    // this.setInputsInline(true);
    this.setPreviousStatement(true);
    this.setNextStatement(true);
  },
}


Blockly.Blocks['visionkit_annotator_camera'] = {
  init:function() {
    this.setColour(Blockly.Blocks.visionkit.HUE);
    this.appendDummyInput()
      .appendField("Annotator(camera,dimensions=(")
      .appendField(new Blockly.FieldTextInput("320"),"X")
      .appendField(",")
      .appendField(new Blockly.FieldTextInput("240"),"Y")
      .appendField(")")
    this.appendDummyInput()
      .appendField("Scale_x")
      .appendField(new Blockly.FieldTextInput("1640"),"SCALE_X")
      .appendField("Scale_y")
      .appendField(new Blockly.FieldTextInput("1232"),"SCALE_Y")
    this.setPreviousStatement(true);
    this.setNextStatement(true);
  }
}

Blockly.Blocks['visionkit_transform_boundingBox'] = {
  init:function() {
    this.setColour(Blockly.Blocks.visionkit.HUE);
    this.appendDummyInput()
      .appendField("Define Bounding Box Transform")
    this.setPreviousStatement(true);
    this.setNextStatement(true);
  }
}

Blockly.Blocks['visionkit_CameraInference'] = {
  init:function() {
    this.setColour(Blockly.Blocks.visionkit.HUE)
    this.appendDummyInput()
      // .appendField("with CameraInference as inference")
      .appendField("Camera Inference set ")
      .appendField(new Blockly.FieldDropdown([
          ["Face Detection","Face Detection"]
        ]),"SETTING")
    this.appendStatementInput("STACK")
    this.setPreviousStatement(true);
    this.setNextStatement(true);
  }
}

Blockly.Blocks['visionkit_avg_joy_score_num'] = {
  init:function() {
    this.setColour(Blockly.Blocks.visionkit.HUE)
    this.appendDummyInput()
      .appendField("avg_joy_score(")
      .appendField(new Blockly.FieldTextInput("faces"),"FACE")
      .appendField(")")
    this.setOutput(true);
  }
}

Blockly.Blocks['visionkit_face'] = {
  init:function() {
    this.setColour(Blockly.Blocks.visionkit.HUE)
    this.appendDummyInput()
      .appendField("faces")
    this.setOutput(true)
  }
}

