class Tep::StudentService < Tep::ApplicationService
  def call
    rest_client_request(:post, url, student, :student, body: body)
  end

  private
    def endpoint
      :student
    end

    def student
      @student ||= @school.students.find_by(id: @id)
    end

    def primary_contact_ids
      student.primary_contacts.where.not(email: ['', nil]).pluck(:id)
    end

    def body
      {}.tap do |props|
        props[:message_id] = SecureRandom.uuid
        props[:student_id] = student.id
        props[:contact_ids] = primary_contact_ids
        props[:first_name] = student.first_name
        props[:last_name] = student.last_name
        props[:grade] = student.grade
        return props if @options[:status].nil?

        props[:status] = @options[:status]
      end
    end
end
