<?php

namespace App\Console\Commands;

use Illuminate\Console\Command;
use App\Models\Style;

class FixStyleImagePaths extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'app:fix-style-image-paths';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Prepend style_previews/ to the preview_image path for all styles';

    /**
     * Execute the console command.
     */
    public function handle()
    {
        $styles = Style::all();

        foreach ($styles as $style) {
            if (!str_starts_with($style->preview_image, 'style_previews/')) {
                $style->preview_image = 'style_previews/' . $style->preview_image;
                $style->save();
            }
        }

        $this->info('Image paths for styles have been updated successfully.');
    }
}