<?php

namespace App\Appointment\Command;

use App\Appointment\Service\AppointmentExpiryService;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

#[AsCommand(
    name: 'app:cancel-expired-appointments',
    description: 'Expires pending bookings whose 15-min payment window lapsed or whose slot time has passed',
)]
class CancelExpiredAppointmentsCommand extends Command
{
    public function __construct(private readonly AppointmentExpiryService $expiryService)
    {
        parent::__construct();
    }

    protected function execute(InputInterface $input, OutputInterface $output): int
    {
        $count = $this->expiryService->expireStale();
        $output->writeln(sprintf('Expired %d appointments.', $count));
        return Command::SUCCESS;
    }
}
