<?php

namespace App\Console\Commands;

use App\Support\ClearAttendanceRecords;
use Illuminate\Console\Command;

class ClearAttendanceRecordsCommand extends Command
{
    /**
     * @var string
     */
    protected $signature = 'attendance:clear-records {--force : Run without confirmation}';

    /**
     * @var string
     */
    protected $description = 'Delete all attendance punches and leave applications (devices and enrollments are kept)';

    public function handle(): int
    {
        if (! $this->option('force') && ! $this->confirm(
            'This will permanently delete all attendance punches and leave applications. Continue?',
            false,
        )) {
            return self::SUCCESS;
        }

        $result = ClearAttendanceRecords::run();

        $this->components->info(sprintf(
            'Removed %d punch(es) and %d leave application(s). Refreshed %d draft salary row(s).',
            $result['punches'],
            $result['leaves'],
            $result['salary_drafts_refreshed'],
        ));

        return self::SUCCESS;
    }
}
