class SchoolsController < ApplicationController
  skip_before_action :authenticate_request!, only: :valid
  skip_before_action :enforce_password_reset!, only: :valid
  skip_before_action :enforce_terms_of_service_agreement!, only: :valid

  def index
    school = current_user.school
    school_config = school.find_or_build_school_config
    props = {
      id: school.id,
      name: school.name,
      app_color: school.find_or_build_school_branding.color.to_s.camelize(:lower),
      php_app_color: school_config.color,
      site_type: school.site_type,
      site_environment: school.site_environment,
      school_year_type: school_config.school_year_type.titleize,
      ed_fi_system: school.ed_fi_system,
      us_department_of_eduction: school.us_department_of_education == 1,
      country_code: school.country&.alpha2,
      country_id: school.country&.id,
      non_binary: school_config.non_binary,
      indiana_environment: school.find_or_build_ed_fi_indiana_environment.environment,
      google_sso: school_config.google_sso,
      school_state_id: school.school_state&.state_id?
    }
    render_success :ok, json: props
  end

  def valid
    school = ::School.find_by(id: params[:id])
    data = {
      id: school&.id,
      valid: !!school,
      name: school&.name || '',
      app_color: school&.find_or_build_school_branding&.color&.to_s&.camelize(:lower),
      google_sso: school.find_or_build_school_config.google_sso
    }
    render_success :ok, json: data
  end
end
