<?php

namespace Hubleto\App\Community\Settings\Models;


use Hubleto\Framework\Db\Column\Lookup;
use Hubleto\Framework\Db\Column\Text;
use Hubleto\Framework\Db\Column\Color;
use Hubleto\Framework\Db\Column\Varchar;
use Hubleto\App\Community\Auth\Models\User;

class Team extends \Hubleto\Erp\Model
{
  public string $table = 'teams';
  public string $recordManagerClass = RecordManagers\Team::class;
  public ?string $lookupSqlValue = '{%TABLE%}.name';

  public function describeColumns(): array
  {
    return array_merge(parent::describeColumns(), [
      'name' => (new Varchar($this, $this->translate("Team name")))->setRequired(),
      'color' => (new Color($this, $this->translate("Team color"))),
      'description' => (new Text($this, $this->translate("Description"))),
      'id_manager' => (new Lookup($this, $this->translate("Manager"), User::class))->setReactComponent('InputUserSelect')->setRequired(),
    ]);
  }

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

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

    $description->columns = [
      'name' => $description->columns['name'],
      'color' => $description->columns['color'],
      'description' => $description->columns['description'],
      'id_manager' => $description->columns['id_manager'],
      'members' => (new Varchar($this, $this->translate('Members'))),
    ];

    return $description;
  }
}
