<?php

namespace Database\Seeders;

use App\Models\AiModel;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Seeder;

class AiModelSeeder extends Seeder
{
    /**
     * Run the database seeds.
     */
    public function run(): void
    {
        Schema::disableForeignKeyConstraints();
        AiModel::query()->delete();

        if (DB::getDriverName() === 'mysql') {
            DB::statement('ALTER TABLE ai_models AUTO_INCREMENT = 1');
        }

        Schema::enableForeignKeyConstraints();

        $data = [
            [
                'id' => 2,
                'name' => 'FLUX.1 Kontext [dev]',
                'model_type' => 'flux',
                'created_at' => '2025-07-27T20:46:32.000000',
                'updated_at' => '2025-07-28T18:07:14.000000',
                'model_id' => 'runware:106@1',
                'api_provider_id' => null, // Verwende null statt 0 oder ungültiger IDs
                'enabled' => 1,
                'parameters' => null,
            ],
            [
                'id' => 5,
                'name' => 'AbsoluteReality',
                'model_type' => 'sd1.5',
                'created_at' => '2025-07-27T20:46:32.000000',
                'updated_at' => '2025-07-27T20:46:32.000000',
                'model_id' => 'civitai:81458@256668',
                'api_provider_id' => null,
                'enabled' => 1,
                'parameters' => null,
            ],
            [
                'id' => 6,
                'name' => 'DreamShaper 8',
                'model_type' => 'sd1.5',
                'created_at' => '2025-07-27T20:46:32.000000',
                'updated_at' => '2025-07-27T20:46:32.000000',
                'model_id' => 'civitai:4384@252914',
                'api_provider_id' => null,
                'enabled' => 1,
                'parameters' => null,
            ],
            [
                'id' => 7,
                'name' => 'FLUX.1 Kontext [dev] in ComfyUI',
                'model_type' => 'flux',
                'created_at' => '2025-07-31T18:51:48.000000',
                'updated_at' => '2025-08-06T11:26:30.000000',
                'model_id' => 'flux1-kontext-dev',
                'api_provider_id' => null,
                'enabled' => 1,
                'parameters' => '{
                    "1": {
                        "inputs": {
                        "vae_name": "ae.safetensors"
                        },
                        "class_type": "VAELoader",
                        "_meta": {
                        "title": "Load VAE"
                        }
                    },
                    "2": {
                        "inputs": {
                        "clip_name1": "clip_l.safetensors",
                        "clip_name2": "t5xxl_fp8_e4m3fn_scaled.safetensors",
                        "type": "flux",
                        "device": "default"
                        },
                        "class_type": "DualCLIPLoader",
                        "_meta": {
                        "title": "DualCLIPLoader"
                        }
                    },
                    "3": {
                        "inputs": {
                        "conditioning": [
                            "25",
                            0
                        ]
                        },
                        "class_type": "ConditioningZeroOut",
                        "_meta": {
                        "title": "ConditioningZeroOut"
                        }
                    },
                    "4": {
                        "inputs": {
                        "images": [
                            "9",
                            0
                        ]
                        },
                        "class_type": "PreviewImage",
                        "_meta": {
                        "title": "Preview Image"
                        }
                    },
                    "5": {
                        "inputs": {
                        "filename_prefix": "ComfyUI",
                        "images": [
                            "7",
                            0
                        ]
                        },
                        "class_type": "SaveImage",
                        "_meta": {
                        "title": "Save Image"
                        }
                    },
                    "7": {
                        "inputs": {
                        "samples": [
                            "20",
                            0
                        ],
                        "vae": [
                            "1",
                            0
                        ]
                        },
                        "class_type": "VAEDecode",
                        "_meta": {
                        "title": "VAE Decode"
                        }
                    },
                    "8": {
                        "inputs": {
                        "pixels": [
                            "9",
                            0
                        ],
                        "vae": [
                            "1",
                            0
                        ]
                        },
                        "class_type": "VAEEncode",
                        "_meta": {
                        "title": "VAE Encode"
                        }
                    },
                    "9": {
                        "inputs": {
                        "image": [
                            "27",
                            0
                        ]
                        },
                        "class_type": "FluxKontextImageScale",
                        "_meta": {
                        "title": "FluxKontextImageScale"
                        }
                    },
                    "11": {
                        "inputs": {
                        "direction": "right",
                        "match_image_size": true,
                        "spacing_width": 0,
                        "spacing_color": "white",
                        "image1": [
                            "24",
                            0
                        ]
                        },
                        "class_type": "ImageStitch",
                        "_meta": {
                        "title": "Image Stitch"
                        }
                    },
                    "12": {
                        "inputs": {
                        "guidance": 2.5,
                        "conditioning": [
                            "17",
                            0
                        ]
                        },
                        "class_type": "FluxGuidance",
                        "_meta": {
                        "title": "FluxGuidance"
                        }
                    },
                    "17": {
                        "inputs": {
                        "conditioning": [
                            "25",
                            0
                        ],
                        "latent": [
                            "8",
                            0
                        ]
                        },
                        "class_type": "ReferenceLatent",
                        "_meta": {
                        "title": "ReferenceLatent"
                        }
                    },
                    "20": {
                        "inputs": {
                        "seed": 71319103185943,
                        "steps": 8,
                        "cfg": 1,
                        "sampler_name": "euler",
                        "scheduler": "simple",
                        "denoise": 1,
                        "model": [
                            "26",
                            0
                        ],
                        "positive": [
                            "12",
                            0
                        ],
                        "negative": [
                            "3",
                            0
                        ],
                        "latent_image": [
                            "8",
                            0
                        ]
                        },
                        "class_type": "KSampler",
                        "_meta": {
                        "title": "KSampler"
                        }
                    },
                    "22": {
                        "inputs": {
                        "model_path": "svdq-int4_r32-flux.1-kontext-dev.safetensors",
                        "cache_threshold": 0,
                        "attention": "nunchaku-fp16",
                        "cpu_offload": "auto",
                        "device_id": 0,
                        "data_type": "bfloat16",
                        "i2f_mode": "enabled"
                        },
                        "class_type": "NunchakuFluxDiTLoader",
                        "_meta": {
                        "title": "Nunchaku FLUX DiT Loader"
                        }
                    },
                    "24": {
                        "inputs": {
                        "image": "__FILENAME__",
                        "refresh": "refresh"
                        },
                        "class_type": "LoadImageOutput",
                        "_meta": {
                        "title": "Load Image (from Outputs)"
                        }
                    },
                    "25": {
                        "inputs": {
                        "text": "__PROMPT__",
                        "clip": [
                            "2",
                            0
                        ]
                        },
                        "class_type": "CLIPTextEncode",
                        "_meta": {
                        "title": "CLIP Text Encode (Positive Prompt)"
                        }
                    },
                    "26": {
                        "inputs": {
                        "lora_name": "flux.1-kontext-dev-turbo_lora.safetensors",
                        "lora_strength": 1,
                        "model": [
                            "22",
                            0
                        ]
                        },
                        "class_type": "NunchakuFluxLoraLoader",
                        "_meta": {
                        "title": "Nunchaku FLUX.1 LoRA Loader"
                        }
                    },
                    "27": {
                        "inputs": {
                        "upscale_method": "nearest-exact",
                        "megapixels": 1.2000000000000002,
                        "image": [
                            "11",
                            0
                        ]
                        },
                        "class_type": "ImageScaleToTotalPixels",
                        "_meta": {
                        "title": "Scale Image to Total Pixels"
                        }
                    }
                    }',
            ],
            [
                'id' => 8,
                'name' => 'HiDream-I1-Dev',
                'model_type' => 'base',
                'created_at' => '2025-08-08T10:46:29.000000',
                'updated_at' => '2025-08-08T10:46:29.000000',
                'model_id' => 'runware:97@2',
                'api_provider_id' => null,
                'enabled' => 1,
                'parameters' => null,
            ],
        ];

        foreach ($data as $row) {
            AiModel::create($row);
        }
    }
}
