<?php

namespace App\Repositories;

use Prettus\Repository\Eloquent\BaseRepository;
use Prettus\Repository\Criteria\RequestCriteria;
use App\Repositories\ProductRepository;
use App\Models\Product;
use App\Validators\ProductValidator;

/**
 * Class ProductRepositoryEloquent.
 *
 * @package namespace App\Repositories;
 */
class ProductRepositoryEloquent extends BaseRepository implements ProductRepository
{
    /**
     * Specify Model class name
     *
     * @return string
     */

    protected $categoryRepository;
    protected $colourRepo;

    // Inject CategoryRepository in the constructor
    public function __construct(CategoryRepository $categoryRepository, ColourRepository $colourRepository)
    {
        $this->categoryRepository = $categoryRepository;
        $this->colourRepo = $colourRepository;
        parent::__construct(app());
    }
    public function model()
    {
        return Product::class;
    }

    public function indexPage()
    {
        $get_products = parent::all();
        return view('admin.products.index', compact('get_products'));
    }

    public function createPage()
    {
        $categories = $this->categoryRepository->getAllCategories();
        $colors = $this->colourRepo->getAllColours();
        return view('admin.products.add', compact('categories', 'colors'));

    }
    public function editPage($id)
    {
        $find_product = parent::find($id);
        $product_gallery_images = $find_product->getMedia('product_gallery_images');
        $categories = $this->categoryRepository->getAllCategories();
        $colors = $this->colourRepo->getAllColours();
        return view('admin.products.update', compact('find_product', 'product_gallery_images','colors', 'categories'));

    }

    public function create($data)
    {
        return parent::create($data);
    }
    public function update($data, $id)
    {
        return parent::update($data, $id);

    }

    public function delete($id)
    {
        return parent::delete($id);
    }

    public function getById($id)
    {
        return parent::find($id);
    }
    public function indexView()
    {
        return parent::orderBy('created_at', 'desc')->take(3)->get();
    }


    public function getAllProducts()
    {
        return parent::all();
    }

    /**
     * Boot up the repository, pushing criteria
     */
    public function boot()
    {
        $this->pushCriteria(app(RequestCriteria::class));
    }

}
