class Support::Sites::Schools::Payjunction::ConfigsController < Support::Sites::Controller
  def show
    render_success :ok, json: props
  end

  def update
    if payjunction.update(payjunction_params)
      render_success :ok, json: props, object: :Environment
    else
      render_error :unprocessable_entity, errors: payjunction
    end
  end

  private
    def school
      @school ||= School.find_by(id: params[:school_id])
    end

    def payjunction
      @payjunction ||= school.find_or_build_payjunction_config
    end

    def payjunction_params
      params.permit(:environment)
    end

    def props
      { id: payjunction.id, environment: payjunction.environment }
    end
end
