<?php

namespace Hubleto\Framework\Controllers\Api\Record;

class Get extends \Hubleto\Framework\Controllers\ApiController {

  public \Hubleto\Framework\Interfaces\ModelInterface $model;

  function __construct()
  {
    parent::__construct();

    $model = $this->router()->urlParamAsString('model');
    $this->model = $this->getModel($model);
  }

  public function response(): array
  {
    $record = [];

    $idEncrypted = $this->router()->urlParamAsString('id');
    $id = (int) \Hubleto\Framework\Helper::decrypt($idEncrypted);

    if ($id > 0) {
      $record = $this->model->record->loadFormData($id);
    }

    return $record;
  }

}
