module Suppliers
  class OrdersController < Suppliers::ApplicationController
    # GET /tables
    # GET /tables.json
    def index
      if params[:state] == 'active'
        @orders = Order.active_for_supplier(current_supplier)
      else
        @orders  = Order.for_supplier(current_supplier, page: params[:page], per_page: params['per_page'] || 25)
      end
      render json: @orders
    end

    def cancel
      @order = current_supplier.find_order(params[:id])
      @order.cancel!
      render json: @order
    end

    def show
      @order = current_supplier.find_order(params[:id])
      render json: @order
    end

    # POST /orders/1/mark_in_process
    def mark_in_process
      @order = Order.find_by_supplier_id_and_id!(current_supplier.id, params[:id])
      @order.is_being_processed!
      head :no_content
    end

    # POST /orders/1/is_delivered
    def mark_delivered
      @order = Order.find_by_supplier_id_and_id(current_supplier.id, params[:id])
      @order.is_delivered!
      head :no_content
    end

  end
end
