<?php

namespace Database\Seeders;

use App\Models\Gallery;
use App\Models\RecoveryGallery;
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
use Illuminate\Database\Seeder;

class GallerySeeder extends Seeder
{
    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run()
    {
        $services = [
            [
                'title' => 'Title',
                'gallery_image' => 'front/images/product10.jpeg',
            ],
            [
                'title' => 'Title',
                'gallery_image' => 'front/images/product11.jpeg',
            ],
            [
                'title' => 'Title',
                'gallery_image' => 'front/images/product12.jpeg',
            ],
            [
                'title' => 'Title',
                'gallery_image' => 'front/images/product13.jpeg',
            ],
            [
                'title' => 'Title',
                'gallery_image' => 'front/images/product14.jpeg',
            ],
            [
                'title' => 'Title',
                'gallery_image' => 'front/images/product15.jpeg',
            ],
            [
                'title' => 'Title',
                'gallery_image' => 'front/images/product16.jpeg',
            ],
            [
                'title' => 'Title',
                'gallery_image' => 'front/images/product17.jpeg',
            ],
            [
                'title' => 'Title',
                'gallery_image' => 'front/images/product18.jpeg',
            ],
            [
                'title' => 'Title',
                'gallery_image' => 'front/images/product19.jpeg',
            ],
            [
                'title' => 'Title',
                'gallery_image' => 'front/images/product20.jpeg',
            ],

        ];


        foreach ($services as $serviceData) {

            $ourService = Gallery::create([
                'title' => $serviceData['title'],

            ]);



            $fullPath = public_path($serviceData['gallery_image']);
            if (file_exists($fullPath)) {
                if (!$ourService->getMedia('gallery_image')->where('file_name', basename($fullPath))->first()) {
                    $ourService->addMedia($fullPath)
                        ->preservingOriginal()
                        ->toMediaCollection('gallery_image');
                }
            }
        }
    }
}
