<?php

namespace Apexl\Io\File;

use Apexl\Io\File\Controllers\FileController;
use Apexl\Io\File\Enums\Permissions\File;
use Apexl\Io\Module;
use Apexl\Io\System\Interfaces\ProvidesRoutesInterface;
use Apexl\Io\User\Interfaces\ProvidesPermissionsInterface;
use Apexl\Io\User\Middleware\RoutePermissionMiddleware;
use Apexl\Io\User\Services\Permissions;

final readonly class FileModule extends Module implements ProvidesRoutesInterface, ProvidesPermissionsInterface
{
    public function permissions(Permissions $permissions): void
    {
        $permissions->registerPermission(
            File::UPLOAD_FILES,
            'Can Upload Files',
            'Files'
        );
    }

    public function routes(): void
    {
        $this->post(sprintf('/api/v%d/file/action/upload[/{id}]', $this->apiVersion()), FileController::class)
            ->setName('files.core.upload')
            ->add(new RoutePermissionMiddleware(File::UPLOAD_FILES));
    }
}
