<?php

namespace App\Http\Controllers;

use App\Models\Application;
use Illuminate\Contracts\View\View;
use Illuminate\Http\Request;

class ApplicationPipelineController extends Controller
{
    public function __invoke(Request $request): View
    {
        $statuses = [
            Application::STATUS_APPLIED => 'Applied',
            Application::STATUS_INTERVIEW => 'Interview',
            Application::STATUS_FOLLOW_UP_NEEDED => 'Follow-up',
            Application::STATUS_OFFER => 'Offer',
            Application::STATUS_REJECTED => 'Rejected',
        ];

        $applications = $request->user()
            ->applications()
            ->with('importedJob.source')
            ->latest('applied_at')
            ->get()
            ->groupBy('status');

        return view('applications.pipeline', [
            'statuses' => $statuses,
            'applications' => $applications,
        ]);
    }
}
