<?php

namespace Database\Seeders;

use Illuminate\Database\Seeder;
use App\Models\PromotionSetting;
use App\Models\PromotionPackage;

class PromotionSeeder extends Seeder
{
    /**
     * Run the database seeds.
     */
    public function run(): void
    {
        // Seed Default Settings
        $settings = [
            [
                'setting_key' => 'max_promotions_per_seller',
                'setting_value' => '5',
                'setting_type' => 'integer',
                'description' => 'Maximum number of active promotions per seller',
            ],
            [
                'setting_key' => 'page1_max_slots',
                'setting_value' => '5',
                'setting_type' => 'integer',
                'description' => 'Maximum promoted products on Page 1',
            ],
            [
                'setting_key' => 'page2_max_slots',
                'setting_value' => '3',
                'setting_type' => 'integer',
                'description' => 'Maximum promoted products on Page 2',
            ],
            [
                'setting_key' => 'auto_expire_promotions',
                'setting_value' => 'true',
                'setting_type' => 'boolean',
                'description' => 'Automatically expire promotions after end_date',
            ],
            [
                'setting_key' => 'promotion_approval_required',
                'setting_value' => 'false',
                'setting_type' => 'boolean',
                'description' => 'Require admin approval for new promotions',
            ],
            [
                'setting_key' => 'analytics_enabled',
                'setting_value' => 'true',
                'setting_type' => 'boolean',
                'description' => 'Track impressions and clicks for promotions',
            ],
        ];

        foreach ($settings as $setting) {
            PromotionSetting::updateOrCreate(
                ['setting_key' => $setting['setting_key']],
                $setting
            );
        }

        // Seed Default Promotion Packages
        $packages = [
            [
                'name' => 'Basic Featured',
                'description' => 'Feature your product on Page 1 for 7 days',
                'price' => 500.00,
                'duration_days' => 7,
                'page_position' => 1,
                'max_products' => 1,
                'priority_level' => 1,
                'badge_text' => 'Featured',
                'badge_color' => '#FF6B00',
                'is_active' => true,
            ],
            [
                'name' => 'Premium Featured',
                'description' => 'Premium placement on Page 1 top section for 7 days',
                'price' => 1500.00,
                'duration_days' => 7,
                'page_position' => 1,
                'max_products' => 1,
                'priority_level' => 5,
                'badge_text' => 'Premium',
                'badge_color' => '#FFD700',
                'is_active' => true,
            ],
            [
                'name' => 'Weekly Package',
                'description' => 'Feature up to 3 products for one week',
                'price' => 1200.00,
                'duration_days' => 7,
                'page_position' => 1,
                'max_products' => 3,
                'priority_level' => 3,
                'badge_text' => 'Featured',
                'badge_color' => '#0066FF',
                'is_active' => true,
            ],
            [
                'name' => 'Monthly Pro',
                'description' => 'Feature up to 5 products for 30 days on Page 1',
                'price' => 4000.00,
                'duration_days' => 30,
                'page_position' => 1,
                'max_products' => 5,
                'priority_level' => 7,
                'badge_text' => 'Sponsored',
                'badge_color' => '#00CC66',
                'is_active' => true,
            ],
            [
                'name' => 'Page 2 Budget',
                'description' => 'Affordable Page 2 promotion for 7 days',
                'price' => 250.00,
                'duration_days' => 7,
                'page_position' => 2,
                'max_products' => 1,
                'priority_level' => 2,
                'badge_text' => 'Ad',
                'badge_color' => '#9933FF',
                'is_active' => true,
            ],
        ];

        foreach ($packages as $package) {
            PromotionPackage::updateOrCreate(
                ['name' => $package['name']],
                $package
            );
        }
    }
}
