<?php

namespace App\Controller;

use App\Action\Functions;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
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('/{year}', name: 'home', methods: ['GET'])]
    public function home(int $year): Response
    {
        $fridays = array();
        try {
            foreach ($this->functions->countFriday13($year) as $date) {
                $fridays[] = $date->format("Y-m-d l");
            }
        } catch (\Exception $e) {
            return new Response($e->getMessage());
        }
        return $this->json($fridays);
    }
}