<?php

namespace App\Console\Commands;

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

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

    /**
     * @var string
     */
    protected $description = 'Delete all permanent employee monthly salary payment records';

    public function handle(): int
    {
        if (! $this->option('force') && ! $this->confirm(
            'This will permanently delete all monthly salary records (draft and paid). Continue?',
            false,
        )) {
            return self::SUCCESS;
        }

        $result = ClearSalaryPayments::run();

        $this->components->info(sprintf(
            'Removed %d salary payment record(s).',
            $result['payments'],
        ));

        return self::SUCCESS;
    }
}
