module Api
  module V1
    class ContactsController < ApplicationController
      def create
        contact = Contact.new(contact_params)
        if contact.save
          ContactMailer.with(user: contact_params).contact_email.deliver_later
          render json: { message: "Thank you for your message #{contact_params[:name]}, We'll get back to you soon!" }
        else
          render json: { message: 'Unable to send message, please try again.' }
        end
      end

      private

      def contact_params
        params.require(:contact).permit(:name, :email, :message)
      end
    end
  end
end
