<?php

namespace Database\Seeders;

use App\Domains\Catalog\Models\Category;
use App\Domains\Tenant\Models\Tenant;
use Illuminate\Database\Seeder;

class CategorySeeder extends Seeder
{
    /**
     * Run the database seeds.
     */
    public function run(): void
    {
        $tenant = Tenant::query()->where('codigo', 'sonder')->first();

        if (! $tenant instanceof Tenant) {
            return;
        }

        $categories = [
            'Remeras',
            'Pantalones',
            'Zapatillas',
            'Buzos',
            'Accesorios',
        ];

        foreach ($categories as $nombre) {
            Category::firstOrCreate([
                'nombre' => $nombre,
                'tenant_code' => $tenant->codigo,
            ]);
        }

        $indumentaria = Category::updateOrCreate(
            [
                'nombre' => 'Indumentaria',
                'tenant_code' => $tenant->codigo,
            ],
            ['categoria_id' => null],
        );

        Category::query()
            ->where('nombre', 'Remeras')
            ->where('tenant_code', $tenant->codigo)
            ->update(['categoria_id' => $indumentaria->id]);
    }
}
