<?php

declare(strict_types=1);

namespace App\Framework\Exception;

final class DirectoryCreateException extends FrameworkException
{
    public function __construct(
        string $directory,
        int $code = 0,
        ?\Throwable $previous = null
    ) {
        $context = ExceptionContext::forOperation('filesystem.create_directory', 'FileSystem')
            ->withData([
                'directory' => $directory,
                'permissions' => is_dir(dirname($directory)) ? decoct(fileperms(dirname($directory))) : 'unknown',
                'parent_exists' => is_dir(dirname($directory)),
                'parent_writable' => is_writable(dirname($directory)),
                'disk_free_space' => disk_free_space(dirname($directory)),
            ]);

        parent::__construct(
            message: "Ordner '$directory' konnte nicht angelegt werden.",
            code: $code,
            previous: $previous,
            context: $context
        );
    }
}
