<?php

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

use App\Http\Controllers\Controller;
use App\Http\Requests\StoreFusionTypeRequest;
use App\Http\Requests\UpdateFusionTypeRequest;
use App\Http\Resources\Admin\FusionTypeResource;
use App\Models\FusionType;
use Gate;
use Illuminate\Http\Request;
use Symfony\Component\HttpFoundation\Response;

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

        return new FusionTypeResource(FusionType::with(['fusioncategory', 'parent_name', 'team'])->get());
    }

    public function store(StoreFusionTypeRequest $request)
    {
        $fusionType = FusionType::create($request->all());

        return (new FusionTypeResource($fusionType))
            ->response()
            ->setStatusCode(Response::HTTP_CREATED);
    }

    public function show(FusionType $fusionType)
    {
        abort_if(Gate::denies('fusion_type_show'), Response::HTTP_FORBIDDEN, '403 Forbidden');

        return new FusionTypeResource($fusionType->load(['fusioncategory', 'parent_name', 'team']));
    }

    public function update(UpdateFusionTypeRequest $request, FusionType $fusionType)
    {
        $fusionType->update($request->all());

        return (new FusionTypeResource($fusionType))
            ->response()
            ->setStatusCode(Response::HTTP_ACCEPTED);
    }

    public function destroy(FusionType $fusionType)
    {
        abort_if(Gate::denies('fusion_type_delete'), Response::HTTP_FORBIDDEN, '403 Forbidden');

        $fusionType->delete();

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