<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Illuminate\Support\Facades\Validator;

use App\Models\VideoText;
use App\Models\ContentElement;

class VideoTextsController extends Controller
{
    public function remove($id)
    {
        Validator::make(request()->all(), [
            'pivot.contentable_id' => 'required|integer',
            'pivot.contentable_type' => 'required|string',
        ])->validate();

        $contentable = ContentElement::findContentable(requestInput());

        if (!auth()->user()->can('update', $contentable)) {
            return response()->json(['error' => 'You cannot remove this video text'], 403);
        }

        $video_text = VideoText::findOrFail($id);
        $video_text->delete();

        return response()->json([
            'success' => 'Video Text Removed',
        ]);
    }
}
