class OneRoster::SchoolsController < OneRoster::Controller
  before_action :authorize_roster_scope
  before_action :validate_school_id, only: :show

  after_action :set_total_count_header, only: :index

  def index
    render_success :ok, json: { orgs: bind_and_parse([org_props]) }
  end

  def show
    render_success :ok, json: { org: org_props }
  end

  private
    def set_total_count_header
      response.set_header('X-Total-Count', '1')
    end

    def org_props
      {}.tap do |props|
        props[:dateLastModified] = current_school.updated_at.iso8601
        props[:name] = current_school.name
        props[:sourcedId] = encode_source_id(:school, current_school.id)
        props[:identifier] = current_school.id
        props[:status] = :active
        props[:type] = :school
      end
    end

    def endpoint_props
      [
        :dateLastModified,
        :name,
        :sourcedId,
        :identifier,
        :status,
        :type
      ]
    end
end
