class ContactsController < ApplicationController

  include ActiveModel::Model

  def new
    contact = Contact.new
  end

  def create
    name = params[:name]
    mail = params[:mail]
    message = params[:message]
    if valid?(name, mail, message)
      NoticeMailer.new_contact(name, mail, message).deliver
    else
      redirect_to root_path, alert: "Invalid input! Check Contact form! Name at least 3 characters. Message at least 8 characters."
    end
  end

  private

  def valid?(name, mail, message)
    mail.include?("@") && name.length >=3 && message.length >=8
  end


end
