<?php

namespace Offerte\Offerte\Http\Controllers;

use App\Http\Controllers\PublicController as CMSPublicController;
use Offerte\Offerte\Interfaces\OfferteRepositoryInterface;

class OffertePublicController extends CMSPublicController
{
    /**
     * Constructor.
     *
     * @param type \Offerte\Offerte\Interfaces\OfferteRepositoryInterface $offerte
     *
     * @return type
     */
    public function __construct(OfferteRepositoryInterface $offerte)
    {
        $this->repository = $offerte;
        parent::__construct();
    }

    /**
     * Show offerte's list.
     *
     * @param string $slug
     *
     * @return response
     */
    protected function index()
    {
        $offertes = $this->repository->scopeQuery(function($query){
            return $query->orderBy('id','DESC');
        })->paginate();

        return $this->theme->of('offerte::public.offerte.index', compact('offertes'))->render();
    }

    /**
     * Show offerte.
     *
     * @param string $slug
     *
     * @return response
     */
    protected function show($slug)
    {
        $offerte = $this->repository->scopeQuery(function($query) use ($slug) {
            return $query->orderBy('id','DESC')
                         ->where('slug', $slug);
        })->first(['*']);

        return $this->theme->of('offerte::public.offerte.show', compact('offerte'))->render();
    }
}