class Family::NotificationConfigsController < Family::Controller
  def show
    render_success :ok, json: config_props
  end

  def update
    if config.update(config_params)
      render_success :ok, json: config_props
    else
      render_error :unprocessable_entity, errors: config
    end
  end

  private
    def config
      @config ||= FamilyNotificationConfig.find_or_initialize_by(user: current_user)
    end

    def config_params
      params.permit(:accounting_invoice, :accounting_payment, :service)
    end

    def config_props
      {
        accounting_invoice: config.accounting_invoice,
        accounting_payment: config.accounting_payment,
        service: config.service
      }
    end
end
