class Family::Controller < ApplicationController
  before_action :require_family!
  before_action :require_family_module!

  private
    def require_family!
      return if current_user.role == :family

      render_error :forbidden, errors: 'Permission Required'
    end

    def require_family_module!
      return if area.nil? || current_school.find_or_build_family_module.send(area)

      render_error :forbidden, message: 'Do not have access'
    end

    def validate_school_allows_changes
      return if current_school.find_or_build_family_profile_config.allow_family?

      render_error :forbidden, message: 'Family changes not enabled'
    end

    def current_family
      current_user.family
    end

    def students
      current_family.students(true)
    end

    def student
      @student ||= students.find_by(id: params[:student_id] || params[:id])
    end

    def area
      nil
    end
end
