<?php

namespace Hubleto\App\Community\Usage\Models;

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


class Log extends \Hubleto\Erp\Model
{
  public string $table = 'usage_log';
  public string $recordManagerClass = RecordManagers\Log::class;
  public bool $disableAuditLog = true;

  public function describeColumns(): array
  {
    return array_merge(parent::describeColumns(), [
      'datetime' => (new DateTime($this, $this->translate('Time')))->setRequired(),
      'ip' => (new Varchar($this, $this->translate('IP')))->setRequired(),
      'route' => (new Varchar($this, $this->translate('Route')))->setRequired(),
      'params' => (new Varchar($this, $this->translate('Params'))),
      'message' => (new Varchar($this, $this->translate('Message'))),
      'id_user' => (new Lookup($this, $this->translate('User'), User::class))->setReactComponent('InputUserSelect')->setRequired(),
    ]);
  }

  public function describeTable(): \Hubleto\Framework\Description\Table
  {
    $description = parent::describeTable();
    $description->columns['id'] = $this->columns['id'];
    $description->permissions['canCreate'] = false;
    $description->permissions['canUpdate'] = false;
    $description->permissions['canDelete'] = false;

    $description->show(['header', 'fulltextSearch', 'columnSearch', 'moreActionsButton']);
    $description->hide(['footer']);

    return $description;
  }

}
