<?php

namespace {{ appNamespace }}\Models;

use \Hubleto\Framework\Db\Column\Boolean;
use \Hubleto\Framework\Db\Column\Color;
use \Hubleto\Framework\Db\Column\Decimal;
use \Hubleto\Framework\Db\Column\Date;
use \Hubleto\Framework\Db\Column\DateTime;
use \Hubleto\Framework\Db\Column\File;
use \Hubleto\Framework\Db\Column\Image;
use \Hubleto\Framework\Db\Column\Integer;
use \Hubleto\Framework\Db\Column\Json;
use \Hubleto\Framework\Db\Column\Lookup;
use \Hubleto\Framework\Db\Column\Password;
use \Hubleto\Framework\Db\Column\Text;
use \Hubleto\Framework\Db\Column\Varchar;

use \Hubleto\App\Community\Auth\Models\User;

class {{ model }} extends \Hubleto\Framework\Model
{

  // Enum constants for improving readability of the code
  const ENUM_ONE = 1;
  const ENUM_TWO = 2;
  const ENUM_THREE = 3;

  // Enum lists to be used for columns with enumerable lists.
  // For more details see https://developer.hubleto.eu/docs/models/enums
  const INTEGER_ENUM_VALUES = [
    self::ENUM_ONE => 'One',
    self::ENUM_TWO => 'Two',
    self::ENUM_THREE => 'Three',
  ];

  // Name of the SQL table for this model
  public string $table = '{{ sqlTable }}';

  // Model's record manager class.
  // For more details see https://developer.hubleto.eu/docs/models/record-manager
  public string $recordManagerClass = RecordManagers\{{ model }}::class;

  public ?string $lookupSqlValue = 'concat("{{ model }} #", {{ '{%' }}TABLE{{ '%}' }}.id)';
  public ?string $lookupUrlDetail = '{{ modelPluralFormKebab }}/{{ '{%' }}ID{{ '%}' }}';

  // Definition of model's relations.
  // For more details see https://developer.hubleto.eu/docs/models/relations
  public array $relations = [ 
    'OWNER' => [ self::BELONGS_TO, User::class, 'id_owner', 'id' ],
    'MANAGER' => [ self::BELONGS_TO, User::class, 'id_manager', 'id' ],
  ];

  /**
   * Returns description of the columns in this model.
   * For more details see https://developer.hubleto.eu/docs/models/description-api
   *
   * @return array
   * 
   */
  public function describeColumns(): array
  {
    return array_merge(parent::describeColumns(), [
      'varchar_example' => (new Varchar($this, $this->translate('Varchar')))->setDefaultVisible()
        // ->setReadonly()
        // ->setRequired()
        ->setCssClass('text-2xl text-primary')
      ,
      'text_example' => (new Text($this, $this->translate('Text')))->setDefaultVisible()
        // ->setReadonly()
        // ->setRequired()
        ->setCssClass('text-2xl text-primary')
      ,
      'decimal_example' => (new Decimal($this, $this->translate('Number')))->setDefaultVisible()
        // ->setReadonly()
        // ->setRequired()
        ->setCssClass('text-2xl text-primary')
        ->setDecimals(4)
      // ,
      // 'date_example' => (new Date($this, $this->translate('Date')))->setDefaultVisible()->setReadonly()->setRequired()
      //   ->setDefaultValue(date("Y-m-d"))
      // ,
      // 'datetime_example' => (new DateTime($this, $this->translate('DateTime')))->setDefaultVisible()->setReadonly()->setRequired()
      //   ->setDefaultValue(date("Y-m-d H:i:s"))
      // ,
      // 'integer_example' => (new Integer($this, $this->translate('Integer')))->setDefaultVisible()->setReadonly()->setRequired()
      //   ->setEnumValues(self::INTEGER_ENUM_VALUES)
      //   ->setEnumCssClasses([
      //     self::ENUM_ONE => 'bg-blue-50',
      //     self::ENUM_TWO => 'bg-yellow-50',
      //     self::ENUM_THREE => 'bg-green-50',
      //   ])
      //   ->setDefaultValue(self::ENUM_ONE)
      // ,
      // 'color_example' => (new Color($this, $this->translate('Color')))->setDefaultVisible()->setReadonly()->setRequired(),
      // 'image_example' => (new Image($this, $this->translate('Image')))->setDefaultVisible()->setReadonly()->setRequired(),
      // 'file_example' => (new File($this, $this->translate('File')))->setDefaultVisible()->setReadonly()->setRequired(),
      // 'id_owner' => (new Lookup($this, $this->translate('Owner'), User::class))->setReactComponent('InputUserSelect')->setDefaultVisible()->setReadonly()->setRequired()
      //   ->setDefaultValue($this->getService(\Hubleto\Framework\AuthProvider::class)->getUserId())
      // ,
      // 'id_manager' => (new Lookup($this, $this->translate('Manager'), User::class))->setReactComponent('InputUserSelect')->setDefaultVisible()->setReadonly()->setRequired()
      //   ->setDefaultValue($this->getService(\Hubleto\Framework\AuthProvider::class)->getUserId())
      // ,
    ]);
  }

  /**
   * Returns description of the table showing data from this model.
   * For more details see https://developer.hubleto.eu/docs/models/description-api
   *
   * @return \Hubleto\Framework\Description\Table
   * 
   */
  public function describeTable(): \Hubleto\Framework\Description\Table
  {
    $description = parent::describeTable();
    $description->ui['addButtonText'] = 'Add {{ model }}';
    $description->show(['header', 'fulltextSearch', 'columnSearch', 'moreActionsButton']);
    $description->hide(['footer']);

    // Uncomment and modify these lines if you want to define table filter for your model
    // $description->ui['filters'] = [
    //   'fArchive' => [ 'title' => 'Archive', 'options' => [ 0 => 'Active', 1 => 'Archived' ] ],
    // ];

    return $description;
  }

  /**
   * Returns description of the form showing a data in a record of this model.
   * For more details see https://developer.hubleto.eu/docs/models/description-api
   *
   * @return \Hubleto\Framework\Description\Table
   * 
   */
  // public function describeForm(): \Hubleto\Framework\Description\Form
  // {
  //   return parent::describeForm();
  // }

  /**
   * Callback called before the record is created.
   * For more details see https://developer.hubleto.eu/docs/models/callbacks
   *
   * @param array $record
   * 
   * @return array
   * 
   */
  // public function onBeforeCreate(array $record): array
  // {
  //   return parent::onBeforeCreate($record);
  // }

  /**
   * Callback called after the record is created.
   * For more details see https://developer.hubleto.eu/docs/models/callbacks
   *
   * @param array $record
   * 
   * @return array
   * 
   */
  // public function onAfterCreate(array $savedRecord): array
  // {
  //   return parent::onAfterCreate($savedRecord);
  // }

  /**
   * Callback called before the record is updated.
   * For more details see https://developer.hubleto.eu/docs/models/callbacks
   *
   * @param array $record
   * 
   * @return array
   * 
   */
  // public function onBeforeUpdate(array $record): array
  // {
  //   return parent::onBeforeUpdate($record);
  // }

  /**
   * Callback called after the record is updated.
   * For more details see https://developer.hubleto.eu/docs/models/callbacks
   *
   * @param array $record
   * 
   * @return array
   * 
   */
  // public function onAfterUpdate(array $originalRecord, array $savedRecord): array
  // {
  //   return parent::onAfterUpdate($originalRecord, $savedRecord);
  // }

}
