<?php

namespace Database\Seeders;

use App\Enums\Status;
use Dipokhalder\EnvEditor\EnvEditor;
use Illuminate\Database\Seeder;
use App\Models\WhyBest;

class WhyBestTableSeeder extends Seeder
{
    /**
     * Run the database seeds.
     *
     * @return void
     */
    public array $whyBests = [
        [
            'title'       => 'Various Region Based',
            'description' => 'We have various regional-style food categories'
        ],
        [
            'title'       => 'Corporate Catering',
            'description' => 'Elevating workplace dining with delicious, professional catering'
        ],
        [
            'title'       => 'Home Style Food',
            'description' => 'Homemade flavors straight from our kitchen to your table'
        ],
        [
            'title'       => 'Regular quality cheeck',
            'description' => 'Ensuring consistent excellence with routine quality checks'
        ]
    ];

    public function run()
    {
        $envService = new EnvEditor();
        if ($envService->getValue('DEMO')) {
            foreach ($this->whyBests as $whyBest) {
                $whyBestObject = WhyBest::create([
                    'title'       => $whyBest['title'],
                    'description' => $whyBest['description'],
                    'status'      => Status::ACTIVE,
                ]);
                if (file_exists(public_path('/images/seeder/why-best/' . strtolower(str_replace(' ', '_', $whyBest['title'])) . '.png'))) {
                    $whyBestObject->addMedia(public_path('/images/seeder/why-best/' . strtolower(str_replace(' ', '_', $whyBest['title'])) . '.png'))->preservingOriginal()->toMediaCollection('why-best');
                }
            }
        }
    }
}