<?php

namespace Hubleto\App\Community\Settings\Models;

use Hubleto\Framework\Db\Column\Varchar;

class Currency extends \Hubleto\Erp\Model
{
  public string $table = 'currencies';
  public string $recordManagerClass = RecordManagers\Currency::class;
  public ?string $lookupSqlValue = '{%TABLE%}.code';

  public function describeColumns(): array
  {
    return array_merge(parent::describeColumns(), [
      'name' => (new Varchar($this, $this->translate('Currency'))),
      'code' => (new Varchar($this, $this->translate('Code'))),
      'symbol' => (new Varchar($this, $this->translate('Symbol'))),
    ]);
  }

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

    $description->ui['title'] = $this->translate('Currencies');
    $description->ui['addButtonText'] = $this->translate('Add currency');
    $description->ui['showHeader'] = true;
    $description->ui['showFulltextSearch'] = true;
    $description->ui['showFooter'] = false;

    return $description;
  }

  public function describeForm(): \Hubleto\Framework\Description\Form
  {
    $description = parent::describeForm();

    $id = $this->router()->urlParamAsInteger('id');

    $description->ui['title'] = ($id == -1 ? $this->translate("New currency") : $this->translate("Currency"));
    $description->ui['subTitle'] = ($id == -1 ? $this->translate("Adding") : $this->translate("Editing"));

    return $description;
  }

}
