<?php

namespace {{ appNamespace }};

class Loader extends \Hubleto\Erp\App
{

  // init
  public function init(): void
  {
    parent::init();

    // Add app routes.
    // By default, each app should have a welcome dashboard.
    // If your app will have own settings panel, it should be under the `settings/your-app` slug.
    $this->router()->get([
      '/^{{ appRootUrlSlug }}\/?$/' => Controllers\Home::class,
      '/^settings\/{{ appRootUrlSlug }}\/?$/' => Controllers\Settings::class,
    ]);

    // DO NOT DELETE FOLLOWING LINE, OR `php hubleto` WILL NOT GENERATE CODE HERE
    //@hubleto-cli:routes

    // Add placeholder for custom settings.
    // This will be displayed in the Settings app, under the "All settings" card.
    $settingsApp = $this->appManager()->getApp(\Hubleto\App\Community\Settings\Loader::class);
    $settingsApp->addSetting($this, [
      'title' => '{{ appName }}', // or $this->translate('{{ appName }}')
      'icon' => 'fas fa-table',
      'url' => 'settings/{{ appRootUrlSlug }}',
    ]);

    // Uncomment following if your app will provide own calendar.
    // /** @var \Hubleto\App\Community\Calendar\Manager $calendarManager */
    // $calendarManager = $this->getService(\Hubleto\App\Community\Calendar\Manager::class);
    // $calendarManager->addCalendar(
    //   $this, // reference to this app
    //   '{{ appName }}-calendar', // UID of your app's calendar. Will be referenced as "source" when fetching app's events.
    //   Calendar::class // your app's Calendar class
    // );

    // Uncomment following to configure your app's menu.
    // $appMenu = $this->getService(\Hubleto\App\Community\Desktop\AppMenuManager::class);
    // $appMenu->addItem($this, '{{ appRootUrlSlug }}/item-1', $this->translate('Item 1'), 'fas fa-table');
    // $appMenu->addItem($this, '{{ appRootUrlSlug }}/item-2', $this->translate('Item 2'), 'fas fa-list');
  }

  // installApp
  public function installApp(int $round): void
  {
    if ($round == 1) {
      // install your models here
      // Example: $this->getModel(Models\Contact::class)->upgradeSchema();

      // DO NOT DELETE FOLLOWING LINE, OR `php hubleto` WILL NOT GENERATE CODE HERE
      //@hubleto-cli:upgrade-schema
    }
    if ($round == 2) {
      // do something in the 2nd round, if required
    }
    if ($round == 3) {
      // do something in the 3rd round, if required
    }
  }

  // generateDemoData
  public function generateDemoData(): void
  {
    // Create any demo data to promote your app.
  }

}