<?php

namespace KupShop\ContentBundle\Controller;

use KupShop\ContentBundle\View\DeliveryTimeView;
use KupShop\ContentBundle\View\ProductView;
use KupShop\ContentBundle\View\VariationBlockView;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;

class ProductController extends AbstractController
{
    /**
     * @Route("/{name}_z{id}/", name="products", requirements={"name":"([a-zA-Z0-9-]+)", "id":"([0-9]+)"})
     */
    public function productAction(Request $request, ProductView $view, $id)
    {
        $view->setRequest($request);
        $view->setProductId($id);

        return $view;
    }

    /**
     * @Route("/_shop/delivery/{idp}", requirements={"idp":"\d+"})
     * @Route("/_shop/delivery/{idp}/{idv}", requirements={"idp":"\d+", "idv":"\d+"})
     */
    public function variationDeliveryTimeAction(Request $request, DeliveryTimeView $view, $idp, $idv = null)
    {
        $view->setVariationId($idv);
        $view->setProductId($idp);

        return $view->getResponse();
    }

    /**
     * @Route("/_shop/variation/{productId}/{variationId}/", requirements={"productId":"\d+", "variationId":"\d+"})
     */
    public function variationFragmentAction(VariationBlockView $view, int $productId, int $variationId): Response
    {
        $view->setProductId($productId);
        $view->setVariationId($variationId);

        return $view->getResponse();
    }
}
