<?php

namespace Chatter\Core\Http\Controllers\Api;

use Auth;
use Chatter\Core\Helpers\ChatterHelper;
use Illuminate\Http\Request;
use Chatter\Core\Models\Category;
use Illuminate\Routing\Controller;
use Chatter\Core\Models\CategoryResource;
use Chatter\Core\Models\CategoryInterface;
use Illuminate\Database\Eloquent\ModelNotFoundException;

class CategoryController extends Controller
{
    public function __construct()
    {
        $this->middleware('auth:api')
            ->except(['index', 'show'])
        ;
    }

    /**
     * Display discussions
     *
     * @return \Illuminate\Http\Response
     */
    public function index(Request $request)
    {
        throw new \LogicException('Method not implemented yet.');
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function store(Request $request)
    {
        throw new \LogicException('Method not implemented yet.');
    }

    /**
     * Display the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function show($id)
    {
        $category = Category::where('id', ChatterHelper::toQueryableId($id))
            ->orWhere('slug', $id)
            ->first();

        if (null === $category) {
            $e = new ModelNotFoundException();
            $e->setModel(Category::class, [$id]);
            throw $e;
        }

        return new CategoryResource($category);
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function update(Request $request, $id)
    {
        throw new \LogicException('Method not implemented yet.');
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function destroy($id)
    {
        throw new \LogicException('Method not implemented yet.');
    }
}
