<?php
namespace apexl\Io\modules\subscriptionDisplay;

use apexl\Io\includes\Controller;
use apexl\Io\modules\display\controllers\displayController;
use apexl\Io\modules\menu\services\Menu;
use apexl\Io\modules\subscription\entities\subscriptionEntity;
use apexl\Io\modules\subscriptionDisplay\controllers\adminSubscriptionController;
use apexl\Io\modules\subscriptionDisplay\controllers\cancellationsController;
use apexl\Io\modules\subscriptionDisplay\forms\filters;
use apexl\Io\modules\user\classes\userManagedDisplayModule;

class subscriptionDisplayModule extends userManagedDisplayModule {
    public function __construct()
    {
        parent::__construct();
    }

    public function routes() {
        $this->addProtectedEntityRoutes((new subscriptionEntity()), [
            'all' => [adminSubscriptionController::class.':overview', 'ViewSubscriptions'],
            'get' => [adminSubscriptionController::class.':subscriptionViewSingle', 'ViewSubscriptions'],
            'put' => [adminSubscriptionController::class.':createUpdateSubscription', 'UpdateSubscriptions'],
        ]);

        $this->addProtectedFormRoute('subscriptionDisplay.form.subscriptions.filter', 'subscription-filter', filters::class.':subscription', 'ViewSubscriptions');
        $this->addProtectedFormRoute('subscriptionDisplay.form.subscriptions.createUpdate', 'createUpdate/{id}', adminSubscriptionController::class.':createUpdateSubscriptionForm', 'UpdateSubscriptions');
        $this->addProtectedFormRoute('subscriptionDisplay.form.subscriptions.change', 'change/{id}', adminSubscriptionController::class.':changeSubscriptionForm', 'IsLoggedIn');
        $this->addProtectedFormRoute('subscriptionDisplay.form.subscriptions.restart', 'restart/{id}[/{meta}]', adminSubscriptionController::class.':restartSubscriptionForm', 'IsLoggedIn');


        $this->addProtectedAdminRootRoute('GET', 'subscriptionDisplay.troubleshoot', 'troubleshoot', adminSubscriptionController::class.':troubleshoot', 'UpdateSubscriptions');

        $this->addProtectedAdminRootRoute('GET', 'subscriptionDisplay.suspend', 'subscription/suspend/{id}', adminSubscriptionController::class.':suspendSubscription', 'IsLoggedIn');
        $this->addProtectedAdminRootRoute('GET', 'subscriptionDisplay.change', 'subscription/change/{id}', adminSubscriptionController::class.':changeSubscription', 'IsLoggedIn');
        $this->addProtectedAdminRootRoute('GET', 'subscriptionDisplay.restart', 'subscription/restart/{id}[/{meta}]', adminSubscriptionController::class.':restartSubscription', 'IsLoggedIn');
        $this->addProtectedAdminRootRoute('GET', 'subscriptionDisplay.cancellation-list', 'subscription/cancellation-list', cancellationsController::class.':selectSubscriptionToCancel', 'IsLoggedIn');
    }

    /**
     * @param Menu $menu
     */
    public function registerMenuItems(Menu $menu)
    {
        $menu::addToMenu('subscriptionEntity.display.all', [
            'title' => 'Payment CC Subscriptions',
            'icon' => 'credit-card-front',
            'weight' => 0,
            'parent' => 'payment.display.parent',
        ], 'administration');
    }
}