<?php

namespace App\Http\Controllers;

use App\Http\Requests\ProgramRequest;
use App\Models\Program;
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
use Illuminate\Support\Facades\View;

class ProgramController extends Controller
{
    use AuthorizesRequests;

    public function index()
    {
        $this->authorize('viewAny', Program::class);

        return View::make('programs.index', ['programs' => Program::all()]);
    }

    public function store(ProgramRequest $request)
    {
        $this->authorize('create', Program::class);

        return Program::create($request->validated());
    }

    public function show(Program $program)
    {
        $this->authorize('view', $program);

        return $program;
    }

    public function update(ProgramRequest $request, Program $program)
    {
        $this->authorize('update', $program);

        $program->update($request->validated());

        return $program;
    }

    public function destroy(Program $program)
    {
        $this->authorize('delete', $program);

        $program->delete();

        return response()->json();
    }
}
