<?php

namespace App\Http\Controllers\Api\Assessment;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use App\Models\Assessment;

class AssessmentController extends Controller
{
    // 🔹 list assessment per job / company
    public function index(Request $request)
    {
        return Assessment::with('questions')
            ->latest()
            ->paginate(10);
    }

    // 🔹 create assessment (company)
    public function store(Request $request)
    {
        $data = $request->validate([
            'title' => 'required',
            'assessment_type' => 'required',
            'company_id' => 'required'
        ]);

        return Assessment::create($data);
    }

    // 🔹 detail
    public function show($id)
    {
        return Assessment::with('questions')->findOrFail($id);
    }

    // 🔹 update
    public function update(Request $request, $id)
    {
        $assessment = Assessment::findOrFail($id);

        $assessment->update($request->all());

        return $assessment;
    }

    // 🔹 delete
    public function destroy($id)
    {
        Assessment::destroy($id);

        return response()->json(['message'=>'deleted']);
    }
}