<?php

namespace Database\Seeders;

use Illuminate\Database\Seeder;
use App\Models\OnlineCourse;
use Carbon\Carbon;

class OnlineCoursesTableSeeder extends Seeder
{
    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run()
    {
        $courses = [
            'Machine Learning Fundamentals',
            'Blockchain Basics',
            'Introduction to Cybersecurity',
            'Cloud Computing Essentials',
            'Artificial Intelligence for Everyone',
            'Internet of Things (IoT) Applications',
            'Big Data Analytics'
        ];

        $offeredBys = [
            'Coursera', 
            'edX', 
            'Udemy', 
            'NPTEL', 
            'Google Digital Garage', 
            'LinkedIn Learning', 
            'Microsoft Learn'
        ];

        // Number of records to seed
        $numberOfRecords = 10;

        for ($i = 1; $i <= $numberOfRecords; $i++) {
            // Generate random start and end dates
            $startDate = Carbon::now()->subMonths(rand(1, 12))->subDays(rand(0, 30));
            $endDate = (clone $startDate)->addDays(rand(5, 90)); // Course duration between 5 to 90 days
            $numDays = $startDate->diffInDays($endDate) + 1;

            OnlineCourse::create([
                'faculty_id' => rand(1, 5),
                'department_id' => rand(1, 5),
                'course' => $courses[array_rand($courses)],
                'offered_by' => $offeredBys[array_rand($offeredBys)],
                'start_date' => $startDate->format('Y-m-d'),
                'end_date' => $endDate->format('Y-m-d'),
                'num_days' => $numDays,
                'proof' => null, // Proof left null
            ]);
        }
    }
}
