class Api::Restaurant::MenuController < Api::ApiController
  #Description
  # Pull the default menu details and also other available (active) menus
  # Input Params - order_id
  def index
    param_checksum = params[:checksum]
    # checksum = File.readlines("public/checksums/menu_json.txt").pop.chomp

    all_menu = Menu.all
    @request_url = ''
    if ENV["SERVER_MODE"] == "cloud"
      @request_url = request.base_url
    end
    # to hash
    menu_array = []
    all_menu.each do |m|
      menu_array.push(m.to_json(:include => {:menu_categories => 
                              { :include => { :menu_items => 
                              { :include => [:menu_item_sets, :menu_item_instances => 
                              { :include => :menu_instance_item_sets}]} } }}))
    end            
                 
    #export Checksum file generate by md5
    menu_checksum = Digest::MD5.hexdigest(menu_array.to_json)

    if menu_checksum != param_checksum
      response.headers['CHECKSUM'] = menu_checksum
      @menus = all_menu    
    end
    # @current_menu = Menu.current_menu    
  end

  #Description
  # This API show current order details
  # Input Params - menu_id
  def show
    @menu = menu_detail(params[:id])
  end


  private
  def menu_detail (menu_id)
    if (menu_id)
      #Pull this menu
      menu = Menu.find_by_id(menu_id)
      return menu
    else
      Menu.current_menu
    end

  end

  def menu_params()
    params.permit(:id)
  end


end
