<?php

namespace App\Console\Commands;

use Illuminate\Console\Attributes\Description;
use Illuminate\Console\Attributes\Signature;
use Illuminate\Console\Command;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\DB;

#[Signature('migrate:categories:configure')]
#[Description('Configure categories table.')]
class MigrateCategoriesConfigure extends Command
{

    public function handle()
    {
        $taxonomyMap = [];
        $taxonomy = "a";
        $section = "";

        while( $taxonomy !== "" ){
            $taxonomy = "";
            $section = "";

            $taxonomy = $this->ask("Write WP taxonomy name. Write nothing if you want to save changes.", "" );
            if( $taxonomy == "" )
                break;

            $section = $this->ask("Write entry section equivalent.");

            $taxonomyMap[$taxonomy] = $section;
        }

        DB::table('migration_settings')
            ->updateOrInsert([
                'key' => 'wp_categories_to_entry_sections'
            ],[
                'value' => json_encode($taxonomyMap), 'updated_at' => now()
            ]);

        $this->info('WP Categories to entry sections has been configured.');
    }
}
