<?php

namespace Database\Seeders;

use App\Models\Setting;
use Illuminate\Database\Seeder;

class SettingSeeder extends Seeder
{
    /**
     * Run the database seeds.
     *
     * @return void
     */

    public function run()
    {
        // Truncate the settings table
        Setting::truncate();

        // Seed new data
        $setting = new Setting();
        $setting->site_title = 'LUXURY CANDLES';
        $setting->email = 'info@luxury-candles.net';
        $setting->phone_num = '2403583046';
        $setting->instaLink = '';
        $setting->twitter = '';
        $setting->facebook = '';
        $setting->pinterest = '';
        $setting->address = "PO Box 1122 Colins Street West Victoria 4321 Australia";
        $setting->footer_description = 'COPYRIGHT 2024 © Luxury Candles. ALL RIGHTS RESERVED.';
        $setting->save();

        $mediaFiles = [
            ['path' => 'front/images/logo.gif', 'collection' => 'header_logo'],
            ['path' => 'front/images/footerlogo.webp', 'collection' => 'footer_logo'],
            ['path' => 'front/images/footerlogo.webp', 'collection' => 'fav_icon'],
        ];

        foreach ($mediaFiles as $mediaFile) {
            $path = $mediaFile['path'];
            $collection = $mediaFile['collection'];
            $fullPath = public_path($path);

            if (file_exists($fullPath)) {
                if (!$setting->getMedia($collection)->where('file_name', basename($fullPath))->first()) {
                    $setting->addMedia($fullPath)
                        ->preservingOriginal()
                        ->toMediaCollection($collection);
                }
            }
        }
    }

}
