<?php

namespace App\Http\Controllers;

use App\Models\VideoGallery;
use App\Http\Requests\StoreVideoGalleryRequest;
use App\Http\Requests\UpdateVideoGalleryRequest;

class VideoGalleryController extends Controller
{
    /**
     * Display a listing of the resource.
     */
    public function index()
    {
        $videoGalleries = VideoGallery::orderBy('created_at', 'desc')->get();
        return view('admin.video-gallery.index', compact('videoGalleries'));
    }

    /**
     * Show the form for creating a new resource.
     */
    public function create()
    {
        //
    }

    /**
     * Store a newly created resource in storage.
     */
    public function store(StoreVideoGalleryRequest $request)
    {
        $data = $request->validated();

        VideoGallery::create($data);

        return redirect()->route('videogalleries.index')->with('success', 'Video created successfully');
    }

    /**
     * Display the specified resource.
     */
    public function show(VideoGallery $videogallery)
    {
        //
    }

    /**
     * Show the form for editing the specified resource.
     */
    public function edit(VideoGallery $videogallery)
    {
        return view('admin.video-gallery.edit', compact('videogallery'));
    }

    /**
     * Update the specified resource in storage.
     */
    public function update(UpdateVideoGalleryRequest $request, VideoGallery $videogallery)
    {
        $data = $request->validated();

        $videogallery->update(array_filter($data));

        return redirect()->route('videogalleries.index')->with('success', 'Video updated successfully.');
    }

    /**
     * Remove the specified resource from storage.
     */
    public function destroy(VideoGallery $videogallery)
    {
        $videogallery->delete();
        return redirect()->route('videogalleries.index')->with('success', 'Video deleted successfully.');
    }
}
