<?php

// app/Console/Commands/UpdateStudentClass.php

namespace App\Console\Commands;

use Illuminate\Console\Command;
use App\Models\Studentdetails;
use Carbon\Carbon;

class UpdateStudentClass extends Command
{
    protected $signature = 'update:student_class';

    protected $description = 'Update student class on 1st June each year';

    public function handle()
    {
        // Get the current date
        $currentDate = Carbon::now();

        // Check if it's 1st June
        if ($currentDate->month == 3 && $currentDate->day == 27) {
            // Increment student class by 1
            Studentdetails::where('active', 1)->increment('student_class');

            // Set active to 0 if class exceeds 12
            Studentdetails::where('student_class', '>', 12)->update(['active' => 0]);

            $this->info('Student class updated successfully.');
        } else {
            $this->info('No updated needed.');
        }
    }
}
