<?php

namespace Database\Seeders\New;

use Illuminate\Database\Console\Seeds\WithoutModelEvents;
use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\DB;
use JsonMachine\Items;
use JsonMachine\JsonDecoder\ExtJsonDecoder;

class OrderAddressSeeder extends Seeder
{
    /**
     * Run the database seeds.
     */
    public function run(): void
    {
        DB::transaction(function () {
            $items = Items::fromFile(
                database_path('data/order_address.json'),
                ['decoder' => new ExtJsonDecoder(true)]
            );

            foreach ($items as $data) {
                DB::table('orders')->where('id', $data['order_id'])->update([
                    'customer_address' => $data['address'],
                ]);
            }
        });
    }
}
