<?php

namespace Hubleto\App\Community\Settings\Models;


use Hubleto\Framework\Db\Column\Lookup;
use Hubleto\Framework\Db\Column\Text;
use Hubleto\Framework\Db\Column\Varchar;
use Hubleto\Framework\Models\User;

class Setting extends \Hubleto\Erp\Model
{
  public string $table = 'settings';
  public string $recordManagerClass = RecordManagers\Setting::class;

  public function describeColumns(): array
  {
    return array_merge(parent::describeColumns(), [
      'key' => (new Varchar($this, $this->translate("Key")))->setRequired(),
      'value' => (new Text($this, $this->translate("Value"))),
      'id_owner' => (new Lookup($this, $this->translate("Only for user"), get_class($this->getService(User::class))))->setReactComponent('InputUserSelect'),
    ]);
  }

  public function indexes(array $indexes = []): array
  {
    return parent::indexes([
      'key' => [
        'type' => 'unique',
        'columns' => [
          'key' => [
            'order' => 'asc',
          ],
        ],
      ],
    ]);
  }

  public function describeTable(): \Hubleto\Framework\Description\Table
  {
    $description = parent::describeTable();

    $description->ui['title'] = $this->translate('Settings');
    $description->ui['addButtonText'] = $this->translate('Add Setting');
    $description->show(['header', 'fulltextSearch', 'columnSearch', 'moreActionsButton']);
    $description->hide(['footer']);

    return $description;
  }
}
