<?php

namespace App\Console\Commands;

use App\Models\Shop\Category;
use Illuminate\Console\Command;

class UntranslateShelves extends Command
{
    protected $signature = 'untranslateShelves';

    protected $description = 'Migrations of shelves';

    public function __construct()
    {
        parent::__construct();
    }

    public function handle()
    {
        $categories = Category::all();
        foreach ($categories as $category) {
            $trans = json_decode($category->name, true);
            $name = $trans['fr'];
            $trans = $category->description ? json_decode($category->description, true) : false;
            $description = $trans ? $trans['fr'] : '';
            $category->update(['name' => $name, 'description' => $description]);
        }
    }
}
