module JamRuby
  # sends out a boring ale
  class  AdminMailer < ActionMailer::Base
    include SendGrid


    DEFAULT_SENDER = "JamKazam <noreply@jamkazam.com>"

    default :from => DEFAULT_SENDER

    sendgrid_category :use_subject_lines
    #sendgrid_enable   :opentrack, :clicktrack  # this makes our emails creepy, imo (seth)
    sendgrid_unique_args :env => Environment.mode

    def alerts(options)
      mail(to: APP_CONFIG.email_alerts_alias,
           from: APP_CONFIG.email_generic_from,
           body: options[:body],
           content_type: "text/plain",
           subject: options[:subject])
    end

    def jamclass_alerts(options)
      mail(to: APP_CONFIG.email_jamclass_alerts_alias,
           from: APP_CONFIG.email_generic_from,
           body: options[:body],
           content_type: "text/plain",
           subject: options[:subject])
    end

    def crash_alert(options)
      mail(to: APP_CONFIG.email_crashes_alias,
           from: APP_CONFIG.email_generic_from,
           body: options[:body],
           content_type: "text/plain",
           subject: options[:subject])
    end

    def social(options)
      mail(to: APP_CONFIG.email_social_alias,
           from: options[:from] || APP_CONFIG.email_generic_from,
           body: options[:body],
           content_type: "text/plain",
           subject: options[:subject])
    end

    def partner(options)
      mail(to: APP_CONFIG.email_partners_alias,
           from: APP_CONFIG.email_generic_from,
           body: options[:body],
           content_type: "text/plain",
           subject: options[:subject])
    end

    def ugly(options)
      mail(to: options[:to],
           cc: options[:cc],
           from: APP_CONFIG.email_generic_from,
           body: options[:body],
           content_type: "text/plain",
           subject: options[:subject])
    end


    def pretty(options)
      mail(to: options[:to],
           cc: options[:cc],
           from: APP_CONFIG.email_generic_from,
           body: options[:body],
           content_type: "text/html",
           subject: options[:subject])
    end

    def recurly_alerts(user, options)

      body = options[:body]
      body << "\n\n"
      body << "User " << user.admin_url + "\n"
      body << "User's JamTracks " << user.jam_track_rights_admin_url + "\n"

      mail(to: APP_CONFIG.email_recurly_notice,
           from: APP_CONFIG.email_generic_from,
           body: body,
           content_type: "text/plain",
           subject: options[:subject])
    end
  end
end
