<?php

namespace App\Modules\Gamification\controllers;

use Illuminate\Support\Facades\View;
use App\Facades\DBconfig;
use Illuminate\Http\Request;
use App\Http\Controllers\BaseController;

class SettingsController extends BaseController
{
    /**
     *	The layout that should be used for responses.
     */
    protected $layout = 'layouts.master';

    /**
     * Render the gamification settings page.
     *
     * @return null
     */
    public function index(Request $request)
    {
        $settings = DBconfig::get('gamification');
        $this->layout->content = View::make('gamification::settings.index', compact('settings'));
    }

    /**
     * Updates the settings.
     *
     * @return array
     */
    public function store(Request $request)
    {
        if ($request->has('enabled')) {
            DBconfig::store('gamification.enabled', $request->input('enabled', false));
        }
        if ($request->has('ratio')) {
            DBconfig::store('gamification.ratio', $request->input('ratio', 1));
        }
        if ($request->has('points_per_minute')) {
            DBconfig::store('gamification.points_per_minute', $request->input('points_per_minute', 1));
        }

        return DBconfig::get('gamification');
    }
}
