<?php

namespace App\Console\Commands\Utils;

use App\Models\Nut;
use App\Models\Nuts3Region;
use App\Models\State;
use Illuminate\Console\Command;

class SetStateNuts extends Command
{
    const MAPPING = [
        'DE-BW' => 'DE1',
        'DE-BY' => 'DE2',
        'DE-NW' => 'DEA',
        'DE-NI' => 'DE9',
        'DE-HB' => 'DE5',
        'DE-SH' => 'DEF',
        'DE-SN' => 'DED',
        'DE-BB' => 'DE4',
        'DE-BE' => 'DE3',
        'DE-SL' => 'DEC',
        'DE-RP' => 'DEB',
        'DE-HE' => 'DE7',
        'DE-TH' => 'DEG',
        'DE-HH' => 'DE6',
        'DE-ST' => 'DEE',
        'DE-MV' => 'DE8',

        'CH-AG' => 'CH033',
        'CH-AR' => 'CH053',
        'CH-AI' => 'CH054',
        'CH-BL' => 'CH032',
        'CH-BS' => 'CH031',
        'CH-BE' => 'CH021',
        'CH-FR' => 'CH022',
        'CH-GE' => 'CH013',
        'CH-GL' => 'CH051',
        'CH-GR' => 'CH056',
        'CH-JU' => 'CH025',
        'CH-LU' => 'CH061',
        'CH-NE' => 'CH024',
        'CH-NW' => 'CH065',
        'CH-OW' => 'CH064',
        'CH-SG' => 'CH055',
        'CH-SH' => 'CH052',
        'CH-SZ' => 'CH063',
        'CH-SO' => 'CH023',
        'CH-TG' => 'CH057',
        'CH-TI' => 'CH070',
        'CH-UR' => 'CH062',
        'CH-VS' => 'CH012',
        'CH-VD' => 'CH011',
        'CH-ZG' => 'CH066',
        'CH-ZH' => 'CH040',

        'AT-1' => 'AT11',
        'AT-2' => 'AT21',
        'AT-3' => 'AT12',
        'AT-4' => 'AT31',
        'AT-5' => 'AT32',
        'AT-6' => 'AT22',
        'AT-7' => 'AT33',
        'AT-8' => 'AT34',
        'AT-9' => 'AT13',
    ];
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'utils:set-state-nuts';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Set the state for all nuts based on their associated cities';
    /**
     * Execute the console command.
     *
     * @return int
     */
    public function handle()
    {
        foreach (self::MAPPING as $stateCode => $nutCode) {
            $state = State::where('code', $stateCode)->first();
            $state->nuts_code = $nutCode;
            $state->save();
        }
        return 0;
    }

}
