class Admin::Payjunction::AccountsController < Admin::Controller
  def index
    objects = accounts.map { |a| account_props(a) }
    render_success :ok, json: objects
  end

  def update
    if account.update(account_params)
      render_success :ok
    else
      render_error :unprocessable_entity, errors: account
    end
  end

  private
    def account_props(account)
      {}.tap do |props|
        props[:id] = account.id
        props[:status] = account.status
        props[:name] = account.name
        props[:type] = account.payment_type.humanize
        props[:external_id] = account.account_id
      end
    end

    def accounts
      current_school.payjunction_accounts
    end

    def account
      @account ||= accounts.find(params[:id])
    end

    def account_params
      params.require(:account).permit(:status)
    end
end
