class Api::SurveyController < Api::ApiController

	# before_action  :authenticate

	def index
       	dining_facility = DiningFacility.find(params[:id])
       	survey_data  	= Survey.find_by_dining_name(dining_facility.name)
       	countries		= Lookup.collection_of("country")
       	if !countries.nil? || !survey_data.nil?
       		render :json => { :status => true, :data => { :countries => countries, :survey_data => survey_data} }
       	else
       		render :json => { :status => true, :error_message => "There is no data" }
       	end
	end

	def create
		dining_facility  = DiningFacility.find(params[:id])
		cashier_zone      = CashierTerminalByZone.find_by_zone_id(dining_facility.zone_id)
		shift_by_terminal = ShiftSale.find_by_cashier_terminal_id_and_shift_closed_at(cashier_zone.cashier_terminal_id,nil)
		puts params.to_json
		if params[:survey][:id]>0
			survey = Survey.find(params[:survey][:id])
		else
			survey = Survey.new
		end
		survey.dining_name 		= dining_facility.name
		survey.shift_id 		= shift_by_terminal.id
		survey.child 			= params[:child]
		survey.adult 			= params[:adult]
		survey.male 			= params[:male]
		survey.female 			= params[:female]
		survey.local 			= params[:local]
		survey.created_by 		= current_login_employee.name
		survey.total_customer 	= params[:total_customer]
		survey.total_amount 	= params[:total_amount]
		survey.foreigner 		= params[:foreigner].to_json
		survey.save!

		render :json => { :status => true }
	end

	# private
	#     def survey_params
	#       params.require(:survey).permit(:child, :adult,:male,:female,:local,:foreigner, 
	#       	:dining_name,:created_by,:total_customer,:total_amount)
	#     end

end