<?php
declare(strict_types=1);

namespace Icing\Controller;

use Icing\Model\Table\SettingsTable;

/**
 * Settings Controller
 *
 * @property SettingsTable $Settings
 */
class SettingsController extends AppController
{

    public function index()
    {
        $settings = $this->Settings->find()->all()->indexBy('id')->toArray();

        if ($this->getRequest()->is(['post', 'put'])) {

            $data = $this->getRequest()->getData();
            $settings = $this->Settings->patchEntities($settings, $data);

            if ($this->Settings->saveMany($settings)) {
                $this->Flash->success(__('Settings have been updated.'));
            } else {
                $this->Flash->error(__('Unable to update settings. Please, try again.'));
            }

            return $this->redirect(['action' => 'index']);
        }

        $this->set(compact('settings'));
        $this->viewBuilder()->setOption('serialize', ['settings']);
    }


    public function import()
    {
    }


}
