<?php

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

use App\Http\Controllers\Controller;
use App\Http\Requests\StoreUserSignatureRequest;
use App\Http\Requests\UpdateUserSignatureRequest;
use App\Http\Resources\Admin\UserSignatureResource;
use App\Models\UserSignature;
use Gate;
use Illuminate\Http\Request;
use Symfony\Component\HttpFoundation\Response;

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

        return new UserSignatureResource(UserSignature::with(['user', 'team'])->get());
    }

    public function store(StoreUserSignatureRequest $request)
    {
        $userSignature = UserSignature::create($request->all());

        return (new UserSignatureResource($userSignature))
            ->response()
            ->setStatusCode(Response::HTTP_CREATED);
    }

    public function show(UserSignature $userSignature)
    {
        abort_if(Gate::denies('user_signature_show'), Response::HTTP_FORBIDDEN, '403 Forbidden');

        return new UserSignatureResource($userSignature->load(['user', 'team']));
    }

    public function update(UpdateUserSignatureRequest $request, UserSignature $userSignature)
    {
        $userSignature->update($request->all());

        return (new UserSignatureResource($userSignature))
            ->response()
            ->setStatusCode(Response::HTTP_ACCEPTED);
    }

    public function destroy(UserSignature $userSignature)
    {
        abort_if(Gate::denies('user_signature_delete'), Response::HTTP_FORBIDDEN, '403 Forbidden');

        $userSignature->delete();

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