<?php

namespace App\Http\Controllers\Admin;

use App\Http\Controllers\Controller;
use App\Models\Season;
use Illuminate\Contracts\Foundation\Application;
use Illuminate\Contracts\View\Factory;
use Illuminate\Contracts\View\View;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use function redirect;
use function request;
use function view;

class SeasonController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return Application|Factory|View
     */
    public function index()
    {
        $seasons = Season::paginate(5);
        return view('admin.seasons.index', compact('seasons'));
    }

    /**
     * Show the form for creating a new resource.
     *
     * @return Application|Factory|View
     */
    public function create()
    {
        return view('admin.seasons.create');
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param Request $request
     * @return RedirectResponse
     */
    public function store(Request $request): RedirectResponse
    {
        request()->validate([
            'number' => 'required',
            'description' => 'required',
            'status' => 'required'
        ]);
        Season::create($request->all());
        return redirect()->route('seasons.index');
    }

    /**
     * Display the specified resource.
     *
     * @param int $id
     * @return void
     */
    public function show(int $id)
    {
        //
    }

    /**
     * Show the form for editing the specified resource.
     *
     * @param Season $season
     * @return Application|Factory|View
     */
    public function edit(Season $season)
    {
        return view('admin.seasons.edit', compact('season'));
    }

    /**
     * Update the specified resource in storage.
     *
     * @param Request $request
     * @param Season $season
     * @return RedirectResponse
     */
    public function update(Request $request, Season $season): RedirectResponse
    {
        request()->validate([
            'number' => 'required',
            'description' => 'required',
            'status' => 'required'
        ]);

        $season->update($request->all());
        return redirect()->route('seasons.index');
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param Season $season
     * @return RedirectResponse
     */
    public function destroy(Season $season)
    {
        $season->delete();
        return redirect()->route('season.index');
    }
}
