<?php

namespace App\Console\Commands;

use App\Services\AttendanceComputer;
use Illuminate\Console\Command;
use Illuminate\Support\Carbon;

class ComputeAttendance extends Command
{
    protected $signature = 'attendance:compute {--date= : Date to compute (Y-m-d), defaults to today}';

    protected $description = 'Recompute daily_attendance for a given date from attendance_events, ignoring corrected events.';

    public function handle(AttendanceComputer $computer): int
    {
        $date = $this->option('date') ? Carbon::parse($this->option('date')) : Carbon::today();

        $count = $computer->computeForDate($date);

        $this->info("Computed daily attendance for {$count} employee(s) on {$date->toDateString()}.");

        return self::SUCCESS;
    }
}
