<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use App\Models\User;
use App\Models\Application;

class BasicController extends Controller
{
    public function home() {
        return view('home');
    }
    public function apps() {
        $applications = Application::where('user_id', Auth::user()->id)->get();
        return view('apps', compact('applications'));
    }
    public function apps_review($id, Request $request) {
        $request->validate([
            'review' => 'required'
        ]);

        Application::where('id', $id)->update([
            'review' => $request->review
        ]);

        return redirect('apps');
    }
    public function apps_create() {
        return view('apps-create');
    }
    public function apps_create_post(Request $request) {
        $request->validate([
            'course_name' => 'required|min:5|max:255',
            'date' => 'required|date',
            'payment' => 'required|in:cash,transfit',
        ]);

        Application::create([
            'user_id' => Auth::user()->id,
            'course_name' => $request->course_name,
            'date' => $request->date,
            'payment' => $request->payment,
        ]);

        return redirect('apps');
    }
}
