<?php

namespace Database\Seeders;

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

class BrandTableSeeder extends Seeder
{
    /**
     * Run the database seeds.
     */
    public function run(): void
    {
        $this->seedOldData();
    }

    /**
     * Seed old postshop data
     */
    public function seedOldData(): void
    {
        $datas = json_decode(File::get('database/data/brands.json'));

        $table = 'brands';
        foreach ($datas as $data) {
            DB::table($table)->insert([
                'id' => $data->id,
                'created_at' => $data->created_at,
                'updated_at' => $data->updated_at,
                'name' => $data->name,
                'slug' => $data->slug,
                'website' => $data->website,
                'description' => $data->description,
                'is_visible' => $data->is_enabled,
                'seo_title' => $data->seo_title,
                'seo_description' => $data->seo_description,
                'type' => $data->type,
            ]);
        }

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