<?php

namespace App\Http\Controllers;

use App\Http\Requests\ChecklistCategoryRequest;
use App\Services\ChecklistCategoryService;

class ChecklistCategoryController extends Controller
{

    private $checklistCategoryService;

	public function __construct(ChecklistCategoryService $checklistCategoryService)
	{
		$this->checklistCategoryService = $checklistCategoryService;
	}

    public function index()
    {
        $checklistCategories = $this->checklistCategoryService->with(['items']);

        return response()->json($checklistCategories, 201);
    }

    public function store(ChecklistCategoryRequest $request)
    {
        $checklistcategory = $this->checklistCategoryService->save($request->all());

        return response()->json($checklistcategory, 201);
    }

    public function show($id)
    {
        $checklistcategory = $this->checklistCategoryService->get($id);

        return response()->json($checklistcategory);
    }

    public function destroy($id)
    {
      	$this->checklistCategoryService->delete($id);
        return response()->json(null, 204);
    }
}