<?php

namespace App\Http\Controllers;

use App\Http\Requests\ChecklistRequest;
use App\Services\ChecklistService;

class ChecklistController extends Controller
{

    private $checklistService;

	public function __construct(ChecklistService $checklistService)
	{
		$this->checklistService = $checklistService;
	}

    public function index()
    {
        $checklists = $this->checklistService->getAll();

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

    public function store(ChecklistRequest $request)
    {
        $checklist = $this->checklistService->save($request->all());

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

    public function show($id)
    {
        $checklist = $this->checklistService->get($id);

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

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