<?php

namespace Lucent\Commands;

use Illuminate\Console\Command;
use Lucent\Primitive\Collection;
use Lucent\Schema\FilesSchema;

class GenerateFileSchema extends Command
{

    protected $signature = 'lucent:generate:file {name}';

    protected $description = 'Generate a lucent file schema';


    public function handle()
    {
        $name = $this->argument('name');
        $schema = new FilesSchema(
            name: $name,
            label: $name,
            fields: Collection::make(),
            disk: "lucent",
            path: $name,
            groups: []
        );

        $json = json_encode($schema, JSON_PRETTY_PRINT);
        $configDir = base_path(config('lucent.schemas_path'));
        $schemaPath = $configDir . "/" . $name . '.json';

        if (file_exists($schemaPath)) {
            $this->error("The schema file already exists.");
            return 0;
        }

        file_put_contents($schemaPath, $json);
        $this->info("The schema file has been created.");

    }

}
