<?php

namespace Database\Seeders;

use App\Models\Wisata;
use Illuminate\Database\Seeder;
use Illuminate\Support\Str;

class DestinationRatingSeeder extends Seeder
{
    /**
     * @var array<string, array{rating: float, aliases: array<int, string>}>
     */
    private array $ratings = [
        'gunung-lemongan' => [
            'rating' => 4.5,
            'aliases' => ['Gunung Lemongan'],
        ],
        'gunung-semeru' => [
            'rating' => 4.6,
            'aliases' => ['Gunung Semeru'],
        ],
        'pantai-watu-godeg' => [
            'rating' => 4.4,
            'aliases' => ['Pantai Watu Godeg', 'Watu Godeg'],
        ],
        'pantai-tlepuk' => [
            'rating' => 4.1,
            'aliases' => ['Pantai Tlepuk'],
        ],
        'puncak-b29' => [
            'rating' => 4.7,
            'aliases' => ['Puncak B29'],
        ],
        'ranu-kumbolo' => [
            'rating' => 4.8,
            'aliases' => ['Ranu Kumbolo'],
        ],
        'ranu-pani' => [
            'rating' => 4.6,
            'aliases' => ['Ranu Pani'],
        ],
        'ranu-regulo' => [
            'rating' => 4.7,
            'aliases' => ['Ranu Regulo'],
        ],
        'tumpak-sewu' => [
            'rating' => 4.8,
            'aliases' => ['Tumpak Sewu', 'Air Terjun Tumpak Sewu'],
        ],
        'kapas-biru' => [
            'rating' => 4.8,
            'aliases' => ['Kapas Biru', 'Air Terjun Kapas Biru'],
        ],
    ];

    public function run(): void
    {
        foreach ($this->ratings as $slug => $data) {
            $slugs = collect($data['aliases'])
                ->map(fn (string $title): string => Str::slug($title))
                ->push($slug)
                ->unique()
                ->values();

            Wisata::query()
                ->whereIn('slug', $slugs)
                ->orWhereIn('title', $data['aliases'])
                ->update(['rating' => $data['rating']]);
        }
    }
}
