<?php

namespace App\Controller;

use App\Action\Functions;
use DateTimeImmutable;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Attribute\Route;

class HomeController extends AbstractController
{
    private Functions $functions;

    public function __construct(Functions $functions)
    {
        $this->functions = $functions;
    }

    #[Route('/{day}/{month}/{year}', name: 'home')]
    public function home(int $day, int $month, int $year): Response
    {
        $dateAsString = $year . "-" . $month . "-" . $day;
        try {
            $result = $this->functions->howDaysToNy(new DateTimeImmutable($dateAsString));
        } catch (\Exception $e) {
            return new Response($e->getMessage());
        }
        return $this->json(["Days before NY:" => $result]);
    }
}