<?php
declare(strict_types=1);

namespace App\Framework\Database\Migration;

use App\Framework\Console\ConsoleCommand;
use App\Framework\Core\PathProvider;
use App\Framework\Database\DatabaseManager;

final readonly class ApplyMigrations
{
    public function __construct(
        private PathProvider $pathProvider,
        private DatabaseManager $db
    ) {}

    #[ConsoleCommand('db:migrate', 'Apply all migrations')]
    public function __invoke(): void
    {
        $path = $this->pathProvider->resolvePath('src/Domain/Media/Migrations');

        $this->db->migrate($path);
    }

    #[ConsoleCommand('db:rollback', 'Apply a single migration')]
    public function up(): void
    {
        $path = $this->pathProvider->resolvePath('src/Domain/Media/Migrations');

        $this->db->rollback($path);
    }
}
