<?php

namespace Modules\Product\Services;

use Illuminate\Http\Request;
use Modules\Product\Interfaces\ProductRepositoryInterface;
use Modules\Product\Models\Product;

class ProductService
{
    private ProductRepositoryInterface $productRepository ;

    public function __construct(ProductRepositoryInterface $productRepository)
    {
        $this->productRepository = $productRepository;
    }

    public function get(Request $request)
    {
        $categories = $this->productRepository->get($request);
        return $categories;
    }
    public function getItem(Product $product)
    {
        $product = $this->productRepository->getItem($product);
        return $product;
    }
    public function items(Product $product)
    {
        $items = $this->productRepository->items($product);
        return $items;
    }
    public function additions(Product $product)
    {
        $additons = $this->productRepository->additions($product);
        return $additons;
    }
    public function logs(Product $product)
    {
        $logs = $this->productRepository->logs($product);
        return $logs;
    }
    public function sizes(Product $product)
    {
        $sizes = $this->productRepository->sizes($product);
        return $sizes;
    }
    public function save(Request $request, ?Product $product): Product
    {
        $product = $this->productRepository->save($request,$product);
        return $product;
    }
    public function updateStatus(Request $request, Product $product): Product
    {
        $product = $this->productRepository->updateStatus($request,$product);
        return $product;
    }
    public function destroy(Request $request, int $id): array
    {
        $response = $this->productRepository->destroy($request,$id);
        return $response;
    }
    public function destroyAll(Request $request): array
    {
        $response = $this->productRepository->destroyAll($request);
        return $response;
    }
    public function restore(Request $request, int $id): array
    {
        $response = $this->productRepository->restore($request,$id);
        return $response;
    }
    public function restoreAll(Request $request): array
    {
        $response = $this->productRepository->restoreAll($request);
        return $response;
    }
    public function getItemFav(Request $request)
    {
        $favorite = $this->productRepository->getItemFav($request);
        return $favorite;
    }
    public function favorite(Request $request) :void
    {
        $fav = $this->getItemFav($request);
        if ($fav)
        {
            $this->productRepository->deleteFavorite($request);
        }
        else
        {
            $this->productRepository->favorite($request);
        }
    }
}
