<?php

namespace Database\Seeders;

use Illuminate\Database\Console\Seeds\WithoutModelEvents;
use Illuminate\Database\Seeder;

class QualityMaintenanceDemoSeeder extends Seeder
{
    /**
     * Run the database seeds.
     */
    public function run(): void
    {
        $product = \App\Models\Product::first();
        $machine = \App\Models\Machine::first();
        $user = \App\Models\User::first();

        if ($product && $user) {
            // Quality Checks
            \App\Models\QualityCheck::create([
                'product_id' => $product->id,
                'inspector_id' => $user->id,
                'checked_quantity' => 100,
                'passed_quantity' => 98,
                'failed_quantity' => 2,
                'status' => 'pass',
                'notes' => 'Minor cosmetic issues on 2 units, but overall within tolerance.',
            ]);

            \App\Models\QualityCheck::create([
                'product_id' => $product->id,
                'inspector_id' => $user->id,
                'checked_quantity' => 50,
                'passed_quantity' => 40,
                'failed_quantity' => 10,
                'status' => 'fail',
                'notes' => 'Major dimension deviation in batch B-402.',
            ]);
        }

        if ($machine && $user) {
            // Maintenance Schedule
            $schedule = \App\Models\MaintenanceSchedule::create([
                'machine_id' => $machine->id,
                'maintenance_type' => 'preventive',
                'scheduled_date' => now()->addDays(5),
                'status' => 'pending',
                'description' => 'Monthly lubrication and sensor calibration.',
            ]);

            // Maintenance Log (Completed)
            \App\Models\MaintenanceLog::create([
                'machine_id' => $machine->id,
                'technician_id' => $user->id,
                'start_time' => now()->subDays(2),
                'end_time' => now()->subDays(2)->addHours(2),
                'downtime_minutes' => 120,
                'cost' => 150.00,
                'technician_notes' => 'Emergency belt replacement. Machine back to normal operation.',
            ]);

            $machine->update(['status' => 'idle', 'last_maintenance_at' => now()->subDays(2)]);
        }
    }
}
