<?php

namespace Cushbu\Artwork\Http\Controllers;

use App\Http\Controllers\PublicWebController as PublicController;
use Cushbu\Artwork\Interfaces\ArtworkRepositoryInterface;

class ArtworkPublicWebController extends PublicController
{
    /**
     * Constructor.
     *
     * @param type \Cushbu\Artwork\Interfaces\ArtworkRepositoryInterface $artwork
     *
     * @return type
     */
    public function __construct(ArtworkRepositoryInterface $artwork)
    {
        $this->repository = $artwork;
        parent::__construct();
    }

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

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

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

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