<?php

namespace Database\Seeders;

use App\Models\Admin\Interna;
use App\Models\Admin\Secciones;
use App\Models\Bank;
use App\Models\Combustible;
use App\Models\Doctor;
use App\Models\AppBannerSetting;
use App\Models\AppHeroSection;
use App\Models\AppHowToUseStep;
use App\Models\AppPromotionalBannerSetting;
use App\Models\Persona;
use App\Models\Partner;
use App\Models\ImageSetting;
use App\Models\Lubricante;
use App\Models\Promociones;
use App\Models\Servicio;
use App\Models\ThumbnailSetting;
use Illuminate\Support\Arr;
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
use Illuminate\Database\Seeder;

class ImageSettingsSeeder extends Seeder
{
    protected array $data = [
        [
            'type' => Persona::class,
            'upload_to' => 'uploads/personas',

            'thumbnails' => [
                [
                    'size' => 'small',
                    'width' => 80,
                    'height' => 80,
                ],
                [
                    'size' => 'medium',
                    'width' => 640,
                    'height' => 640,
                ],
                [
                    'size' => 'large',
                    'width' => 960,
                    'height' => 960,
                ],
            ],
        ],

        [
            'type' => Interna::class,
            'upload_to' => 'uploads/internas',

            'thumbnails' => [
                [
                    'size' => 'small',
                    'width' => 80,
                    'height' => 80,
                ],
                [
                    'size' => 'medium',
                    'width' => 640,
                    'height' => 640,
                ],
                [
                    'size' => 'large',
                    'width' => 960,
                    'height' => 960,
                ],
                /* [
                    'size' => 'summernote',
                    'width' => 1200,
                    'height' => 1200,

                    'default_functions' => 0,
                    'cropped' => 0
                ],*/
            ],
        ],

        [
            'type' => Partner::class,
            'upload_to' => 'uploads/partners',

            'thumbnails' => [
                [
                    'size' => 'small',
                    'width' => 200,
                    'height' => 80,
                ],
            ],
        ],

        [
            'type' => Bank::class,
            'upload_to' => Bank::IMAGE_UPLOAD_TO,

            'thumbnails' => [
                [
                    'size' => Bank::IMAGE_SIZE_SMALL,
                    'width' => 200,
                    'height' => 100,
                ],
                [
                    'size' => Bank::IMAGE_SIZE_LARGE,
                    'width' => 400,
                    'height' => 200,
                ],
            ],
        ],

        [
            'type' => Secciones::class,
            'upload_to' => 'uploads/secciones',

            'thumbnails' => [
                [
                    'size' => 'small',
                    'width' => 80,
                    'height' => 80,
                ],
                [
                    'size' => 'medium',
                    'width' => 640,
                    'height' => 640,
                ],
                [
                    'size' => 'large',
                    'width' => 1920,
                    'height' => 960,
                ],
                [
                    'size' => 'summernote',
                    'width' => 1200,
                    'height' => 1200,

                    'default_functions' => 0,
                    'cropped' => 0
                ]
            ],
        ],

        [
            'type' => Doctor::class,
            'upload_to' => 'uploads/doctors',

            'thumbnails' => [
                [
                    'size' => 'small',
                    'width' => 80,
                    'height' => 80,
                ],
                [
                    'size' => 'medium',
                    'width' => 640,
                    'height' => 640,
                ],
                [
                    'size' => 'large',
                    'width' => 960,
                    'height' => 960,
                ],
            ],
        ],
        [
            'type' => Promociones::class,
            'upload_to' => 'uploads/promociones',

            'thumbnails' => [
                [
                    'size' => 'small',
                    'width' => 80,
                    'height' => 100,
                ],
                [
                    'size' => 'medium',
                    'width' => 640,
                    'height' => 800,
                ],
                [
                    'size' => 'large',
                    'width' => 1080,
                    'height' => 1350,
                ],
            ],
        ],

        [
            'type' => AppHeroSection::class,
            'upload_to' => 'uploads/app-hero-section',
            'thumbnails' => [
                [
                    'size' => 'small',
                    'width' => 202,
                    'height' => 36,
                ],
                [
                    'size' => 'large',
                    'width' => 2500,
                    'height' => 800,
                ],
            ],
        ],

        [
            'type' => AppBannerSetting::class,
            'upload_to' => AppBannerSetting::IMAGE_UPLOAD_TO,
            'thumbnails' => [
                [
                    'size' => AppBannerSetting::IMAGE_SIZE_SMALL,
                    'width' => 180,
                    'height' => 360,
                ],
                [
                    'size' => AppBannerSetting::IMAGE_SIZE_LARGE,
                    'width' => 900,
                    'height' => 1800,
                ],
            ],
        ],

        [
            'type' => AppBannerSetting::class,
            'key' => AppBannerSetting::IMAGE_KEY_APP_STORE,
            'upload_to' => AppBannerSetting::IMAGE_UPLOAD_TO,
            'thumbnails' => [
                [
                    'size' => AppBannerSetting::IMAGE_SIZE_SMALL,
                    'width' => 428,
                    'height' => 145,
                ],
                [
                    'size' => AppBannerSetting::IMAGE_SIZE_LARGE,
                    'width' => 855,
                    'height' => 290,
                ],
            ],
        ],

        [
            'type' => AppBannerSetting::class,
            'key' => AppBannerSetting::IMAGE_KEY_PLAY_STORE,
            'upload_to' => AppBannerSetting::IMAGE_UPLOAD_TO,
            'thumbnails' => [
                [
                    'size' => AppBannerSetting::IMAGE_SIZE_SMALL,
                    'width' => 428,
                    'height' => 145,
                ],
                [
                    'size' => AppBannerSetting::IMAGE_SIZE_LARGE,
                    'width' => 855,
                    'height' => 290,
                ],
            ],
        ],

        [
            'type' => AppPromotionalBannerSetting::class,
            'upload_to' => AppPromotionalBannerSetting::IMAGE_UPLOAD_TO,
            'thumbnails' => [
                [
                    'size' => AppPromotionalBannerSetting::IMAGE_SIZE_SMALL,
                    'width' => 1215,
                    'height' => 160,
                ],
                [
                    'size' => AppPromotionalBannerSetting::IMAGE_SIZE_LARGE,
                    'width' => 2430,
                    'height' => 320,
                ],
            ],
        ],

        [
            'type' => AppHowToUseStep::class,
            'upload_to' => AppHowToUseStep::IMAGE_UPLOAD_TO,
            'thumbnails' => [
                [
                    'size' => AppHowToUseStep::IMAGE_SIZE_SMALL,
                    'width' => 180,
                    'height' => 360,
                ],
                [
                    'size' => AppHowToUseStep::IMAGE_SIZE_LARGE,
                    'width' => 900,
                    'height' => 1800,
                ],
            ],
        ],

        [
            'type' => Servicio::class,
            'upload_to' => 'uploads/servicio',

            'thumbnails' => [
                [
                    'size' => 'small',
                    'width' => 80,
                    'height' => 80,
                ],
                [
                    'size' => 'medium',
                    'width' => 196,
                    'height' => 112,
                ],
                [
                    'size' => 'large',
                    'width' => 393,
                    'height' => 224,
                ],
            ],
        ],
        [
            'type' => Combustible::class,
            'upload_to' => 'uploads/combustible',
            'thumbnails' => [
                [
                    'size' => 'small',
                    'width' => 202,
                    'height' => 36,
                ],
                [
                    'size' => 'large',
                    'width' => 404,
                    'height' => 72,
                ],
            ],
        ],
        [
            'type' => Combustible::class,
            'upload_to' => 'uploads/combustible',
            'key' => 'hero',
            'thumbnails' => [
                [
                    'size' => 'large',
                    'width' => 2300,
                    'height' => 1050,
                ],
            ],
        ],
        [
            'type' => Combustible::class,
            'upload_to' => 'uploads/combustible',
            'key' => 'ficha_tecnica',
            'thumbnails' => [],
        ],
        [
            'type' => Lubricante::class,
            'upload_to' => Lubricante::IMAGE_UPLOAD_TO,
            'thumbnails' => [
                [
                    'size' => Lubricante::IMAGE_SIZE_SMALL,
                    'width' => 196,
                    'height' => 112,
                ],
                [
                    'size' => Lubricante::IMAGE_SIZE_MEDIUM,
                    'width' => 393,
                    'height' => 224,
                ],
                [
                    'size' => Lubricante::IMAGE_SIZE_LARGE,
                    'width' => 786,
                    'height' => 448,
                ],
            ],
        ],
    ];

    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run()
    {
        foreach ($this->data as $type => $imageSettings) {
            $settings = Arr::except($imageSettings, 'thumbnails');
            $thumbnails = $imageSettings['thumbnails'];

            /** @var ImageSetting */
            $settingsRecord = ImageSetting::query()
                ->updateOrCreate(
                    ['type' => $settings['type'], 'key' => isset($settings['key']) ? $settings['key'] : null],
                    $settings,
                );

            foreach ($thumbnails as $key => $thumbnail) {
                $thumbnailData = [
                    'image_settings_id' => $settingsRecord->id,
                    'quality' => 90,
                    'order_no' => $key + 1,
                    ...$thumbnail,
                ];

                ThumbnailSetting::query()
                    ->updateOrCreate(
                        [
                            'image_settings_id' => $settingsRecord->id,
                            'size' => $thumbnailData['size']
                        ],
                        $thumbnailData,
                    );
            }
        }
    }
}
