<?php

namespace apexl\Io\modules\display\callbacks;

use apexl\Io\includes\Routes;

class redirects {
    public static function redirects($response, $route, $output){
        switch ($route){
            case strpos($route,'Entity.delete'):
                $entity = $output::getMetadata('core.controller.delete.entityType')['entityType'] ?? FALSE;
                $entityId = $output::getMetadata('core.controller.delete.entityId')['entityId'] ?? FALSE;
                if($entity && $entityId){
                    $instantEntity = new $entity();
                    $instantEntity->load($entityId);
                    $output::addMetadata($instantEntity->getEntityName().'.delete.redirect', 'redirect', Routes::getRoutePattern($instantEntity->getEntityName().'.display.all'));
                }
                break;
        }
    }
}