<?php

namespace App\Http\Controllers\Api\V1\Admin;

use App\Http\Controllers\Controller;
use App\Http\Requests\StoreFusionCategoryRequest;
use App\Http\Requests\UpdateFusionCategoryRequest;
use App\Http\Resources\Admin\FusionCategoryResource;
use App\Models\FusionCategory;
use Gate;
use Illuminate\Http\Request;
use Symfony\Component\HttpFoundation\Response;

class FusionCategoriesApiController extends Controller
{
    public function index()
    {
        abort_if(Gate::denies('fusion_category_access'), Response::HTTP_FORBIDDEN, '403 Forbidden');

        return new FusionCategoryResource(FusionCategory::with(['team'])->get());
    }

    public function store(StoreFusionCategoryRequest $request)
    {
        $fusionCategory = FusionCategory::create($request->all());

        return (new FusionCategoryResource($fusionCategory))
            ->response()
            ->setStatusCode(Response::HTTP_CREATED);
    }

    public function show(FusionCategory $fusionCategory)
    {
        abort_if(Gate::denies('fusion_category_show'), Response::HTTP_FORBIDDEN, '403 Forbidden');

        return new FusionCategoryResource($fusionCategory->load(['team']));
    }

    public function update(UpdateFusionCategoryRequest $request, FusionCategory $fusionCategory)
    {
        $fusionCategory->update($request->all());

        return (new FusionCategoryResource($fusionCategory))
            ->response()
            ->setStatusCode(Response::HTTP_ACCEPTED);
    }

    public function destroy(FusionCategory $fusionCategory)
    {
        abort_if(Gate::denies('fusion_category_delete'), Response::HTTP_FORBIDDEN, '403 Forbidden');

        $fusionCategory->delete();

        return response(null, Response::HTTP_NO_CONTENT);
    }
}
