<?php

namespace Database\Seeders\New;

use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\File;

class FavoritesSeeder extends Seeder
{
    public function run()
    {
        $datas = json_decode(File::get('database/data/favorite_products.json'));
        $table = 'favorites';

        DB::table($table)->truncate();

        foreach ($datas as $data) {
            DB::table($table)->insert([
                'user_id' => $data->customer_id,
                'product_id' => $data->item_id,
            ]);
        }

        DB::statement("
            SELECT setval('{$table}_id_seq', (SELECT MAX(id) from {$table}))
        ");
    }
}
