class UserNotifier < ActionMailer::Base
  
  ActionMailer::Base.delivery_method = :sendmail  

  def signup_notification(user)
    setup_email(user)
    @subject    += " - Please activate your new account"
    @body[:url]  = "#{SITE_URL_BASE}/account/activate/#{user.activation_code}"
  end
  
  def activation(user)
    setup_email(user)
    @subject    += " - Your account has been activated!"
    @body[:url]  = "#{SITE_URL_BASE}/admin"
  end

  def update_notification(user)
    setup_email(user)
    @subject    += " - Your account has been updated!"
    @body[:url]  = "#{SITE_URL_BASE}/admin"
  end

  def reminder(user)
    setup_email(user)
    @subject    += " - Your current Password!"
    @body[:url]  = "#{SITE_URL_BASE}/login"
  end

  def resource_updated(res)
    admin_notice(res)
    @subject    += " - UPDATED Resource: #{res.name} "
  end

  
  protected
  def setup_email(user)
    @recipients  = "\"#{user.fullname}\" <#{user.email}>"
    @from        = "#{SITE_ADMIN_NAME}<#{SITE_ADMIN_EMAIL}>"
    @subject     = "#{SITE_TITLE} Account "
    @sent_on     = Time.now
    @body[:user] = user
  end

  def admin_notice(res)
    @recipients  = "<#{SITE_ADMIN_EMAIL}>"
    @from        = "#{SITE_ADMIN_NAME}<#{SITE_ADMIN_EMAIL}>"
    @subject     = "#{SITE_TITLE}"
    @sent_on     = Time.now
    @body[:resource] = res
  end

end
