class Ability
  include CanCan::Ability

  def initialize(user)
    user ||= Employee.new

    if user.role == "administrator"
        can :manage, :all
    elsif user.role == "manager"
        can :manage, Menu
        can :manage, MenuCategory
        can :manage, MenuItemAttribute
        can :manage, MenuItemInstance
        can :manage, MenuItemOption
        can :manage, SetMenuItem
        can :manage, ItemSet
        can :manage, MenuItemSet
        can :manage, OrderQueueStation
        can :manage, Zone
        can :manage, CashierTerminal
        can :manage, Employee
        # can :manage, MembershipSetting
        # can :manage, MembershipAction
        # can :manage, PaymentMethodSetting
        can :manage, TaxProfile
        can :manage, PrintSetting
        can :manage, Account

        can :manage, Order
        can :manage, Booking
        can :manage, Sale
        

        can :manage, Customer
        can :manage, DiningQueue

        can :manage, OrderReservation

        can :index, :dailysale
        can :index, :saleitem
        can :index, :receipt_no
        can :index, :shiftsale
        can :index, :credit_payment
        can :index, :void_sale
        can :index, :waste_and_spoilage
        can :index, :product_sale

        can :show, :dailysale
        can :show, :saleitem
        can :show, :receipt_no
        can :show, :shiftsale
        can :show, :credit_payment
        can :show, :void_sale
        can :show, :waste_and_spoilage
        can :show, :product_sale

        can :get_customer, Customer
        can :add_customer, Customer  
        can :update_sale_by_customer, Customer  

        can :index, :other_charge
        can :create, :other_charge
        can :index, :discount
        can :create, :discount
        can :remove_discount_items, :discount
        can :remove_all_discount, :discount
        can :member_discount, :discount

        can :first_bill, :payment
        can :show, :payment
        can :create, :payment
        can :reprint, :payment
        can :rounding_adj, :payment
        can :foc, :payment  
        can :print, :payment      
        can :change_tax, :payment

        can :move_dining, :movetable 
        can :moving, :movetable

        can :move_dining, :moveroom

        can :edit, :sale_edit
        can :item_void, :sale_edit
        can :item_void_cancel, :sale_edit
        can :cancel_all_void, :sale_edit
        can :apply_void, :sale_edit
        can :item_foc, :sale_edit
        can :item_edit, :sale_edit

        can :overall_void, :void

        can :manage, Commission
        can :manage, Commissioner
        can :manage, Promotion
        can :manage, Product

        can :manage, Inventory

        can :index, :home
        can :show, :home

        #ability for split_bill
        can :index, :split_bill
        can :create, :split_bill
        can :update_sale, :split_bill

        #oqs Home
        can :index, :home
        can :index, :show
        can :get_order_items, :home
        can :get_items_by_oqs, :home
        can :update_delivery_status, :home
        can :queue_items_query, :home
        can :completed_order, :home
        can :queue_items_count_query, :home

        can :index, :edit
        can :update, :edit

        can :print, :print
        can :print_order_summary, :print

        can :read, ShiftSale  
        can :update, ShiftSale    

    elsif user.role == "cashier"
        
        # can :overall_void, :void
        can :index, :home
        can :show, :home
        can :check_emp_access_code, :home
        can :read, Order
        can :update, Order
        can :manage, Booking
        can :manage, OrderQueueStation
        can :read, Sale  
        can :update, Sale    

        can :manage, Customer 

        can :manage, OrderReservation

        can :get_customer, Customer
        can :add_customer, Customer
        can :update_sale_by_customer, Customer

        can :index, :other_charge
        can :create, :other_charge
        can :index, :discount
        can :create, :discount
        can :remove_discount_items, :discount
        can :remove_all_discount, :discount
         can :member_discount, :discount

        can :first_bill, :payment
        can :show, :payment
        can :create, :payment
        can :reprint, :payment
        can :rounding_adj, :payment
        can :foc, :payment  
        can :print, :payment
        can :change_tax, :payment

        can :move_dining, :movetable 
        can :moving, :movetable

        can :move_dining, :moveroom

        can :manage, Commission
        can :manage, Commissioner
        can :manage, Promotion
        can :manage, Product

        #ability for split_bill
        can :index, :split_bill
        can :create, :split_bill
        can :update_sale, :split_bill

        #oqs Home
        can :index, :home
        can :index, :show
        can :get_order_items, :home
        can :get_items_by_oqs, :home
        can :update_delivery_status, :home
        can :queue_items_query, :home
        can :completed_order, :home
        can :queue_items_count_query, :home

        can :index, :edit
        can :update, :edit

        can :print, :print
        can :print_order_summary, :print

        can :edit, :sale_edit
        can :item_void, :sale_edit
        can :item_void_cancel, :sale_edit
        can :cancel_all_void, :sale_edit
        can :apply_void, :sale_edit
        can :item_foc, :sale_edit
        can :item_edit, :sale_edit

        can :overall_void, :void
                                               
    elsif user.role == "account"

        can :index, :dailysale
        can :index, :saleitem
        can :index, :receipt_no
        can :index, :shiftsale
        can :index, :credit_payment
        can :index, :void_sale
        can :index, :waste_and_spoilage
        can :index, :product_sale
        can :show, :dailysale
        can :show, :saleitem
        can :show, :receipt_no
        can :show, :shiftsale
        can :show, :credit_payment
        can :show, :void_sale
        can :show, :waste_and_spoilage
        can :show, :product_sale

    elsif user.role == "supervisor"

        can :edit, :sale_edit
        can :item_void, :sale_edit
        can :item_foc, :sale_edit
        can :item_edit, :sale_edit
        can :item_void_cancel, :sale_edit
        can :cancel_all_void, :sale_edit        
        can :apply_void, :sale_edit        
        can :overall_void, :void

        can :index, :other_charge
        can :create, :other_charge
        can :index, :discount
        can :create, :discount
        can :remove_discount_items, :discount
        can :remove_all_discount, :discount
        can :member_discount, :discount

        can :move_dining, :movetable 
        can :moving, :movetable

        can :move_dining, :moveroom

        can :manage, Customer
        can :manage, DiningQueue

        can :manage, OrderReservation

        can :first_bill, :payment
        can :create, :payment
        can :show, :payment
        can :reprint, :payment
        can :rounding_adj, :payment
        can :print, :payment
        can :foc, :payment
        can :change_tax, :payment

        can :manage, Commission
        can :manage, Commissioner
        can :manage, Promotion
        can :manage, Product

        can :index, :home
        can :show, :home

        #ability for split_bill
        can :index, :split_bill
        can :create, :split_bill
        can :update_sale, :split_bill

        #oqs Home
        can :index, :home
        can :index, :show
        can :get_order_items, :home
        can :get_items_by_oqs, :home
        can :update_delivery_status, :home
        can :queue_items_query, :home
        can :completed_order, :home
        can :queue_items_count_query, :home

        can :index, :edit
        can :update, :edit

        can :print, :print
        can :print_order_summary, :print

     elsif user.role == "waiter"
        can :index, :home
        can :show, :home  

        can :manage, Customer   
        can :get_customer, Customer
        can :add_customer, Customer
        can :update_sale_by_customer, Customer

        can :index, :other_charge
        can :create, :other_charge
        can :index, :discount
        can :create, :discount
        can :remove_discount_items, :discount
        can :remove_all_discount, :discount
        can :member_discount, :discount

        #ability for  move table
        can :move_dining, :movetable 
        can :moving, :movetable

        can :move_dining, :moveroom

        #ability for split_bill
        can :index, :split_bill
        can :create, :split_bill

        #oqs Home
        can :index, :home
        can :index, :show
        can :get_order_items, :home
        can :get_items_by_oqs, :home
        can :update_delivery_status, :home
        can :queue_items_query, :home
        can :completed_order, :home
        can :queue_items_count_query, :home

        can :index, :edit
        can :update, :edit

        can :print, :print
        can :print_order_summary, :print

    elsif user.role == "kitchen"
    
    #oqs Home
        can :index, :home
        can :index, :show
        can :get_order_items, :home
        can :get_items_by_oqs, :home
        can :update_delivery_status, :home
        can :queue_items_query, :home
        can :completed_order, :home
        can :queue_items_count_query, :home

        can :index, :edit
        can :update, :edit

        can :print, :print
        can :print_order_summary, :print
    end
  end
end
