<?php

namespace Licenzo\Hooks\CLI;

// Prevent direct access
if (!defined('ABSPATH')) {
    exit;
}

use Licenzo\Framework\Database\Migration\Migrator;

class Commands
{

    public function seed()
    {
        if (!class_exists(\Licenzo\Database\Seeder::class)) {
            return [
                'message' => 'Seeder is not available in distribution builds. Use a development install to seed data.',
            ];
        }

        \Licenzo\Database\Seeder::seed();
    }

    public function migrate()
    {
        $app = \Licenzo\App::getInstance();
        try {
            Migrator::migrate($app->basePath('database/migrations'));
        } catch (\Exception $e) {
            return [
                'message' => $e->getMessage(),
                'file'    => $e->getFile(),
                'line'    => $e->getLine(),
                'trace'   => $e->getTraceAsString()
            ];
        }
    }

    public function down()
    {
        $app = \Licenzo\App::getInstance();
        try {
            Migrator::down($app->basePath('database/migrations'));
        } catch (\Exception $e) {
            return [
                'message' => $e->getMessage(),
                'file'    => $e->getFile(),
                'line'    => $e->getLine(),
                'trace'   => $e->getTraceAsString()
            ];
        }
    }
}
