<?php

namespace Database\Seeders;

use App\Enums\OrderStatus;
use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Carbon;

class OrderStatusCatalogSeeder extends Seeder
{
    public function run(): void
    {
        $now = Carbon::now();
        $statuses = [
            // id_order_status, code, name
            [1, 'Ingresado', 'Ingresado'],
            [2, 'Preparando', 'Preparando'],
            [3, 'Empacado', 'Empacado'],
            [4, 'ListoEnvio', 'Listo para enviar'],
            [5, 'ListoRetiro', 'Listo para retirar'],
            [6, 'Enviado', 'Entregado al transporte'],
            [7, 'Retirado', 'Entregado al cliente'],
            [8, 'Cancelado', 'Cancelado'],
            [9, 'OnHold', 'On Hold'],
            [10, 'Redespacho', 'Redespacho'],
            [11, OrderStatus::EntregadoParcial->value, OrderStatus::EntregadoParcial->label()],
            [12, OrderStatus::DespachoMulticanal->value, OrderStatus::DespachoMulticanal->label()],
            [13, OrderStatus::ListoParaUber->value, OrderStatus::ListoParaUber->label()],
        ];

        foreach ($statuses as [$id, $code, $name]) {
            DB::table('tbl_order_statuses')->updateOrInsert(
                ['id_order_status' => $id],
                [
                    'code' => $code,
                    'name' => $name,
                    'is_active' => true,
                    'created_at' => $now,
                    'updated_at' => $now,
                ]
            );
        }
    }
}
