<?php

namespace App\Http\Controllers;

use App\Models\Competency;
use Illuminate\Http\Request;

class CompetencyController extends Controller
{
    public function index()
    {
        return Competency::all();
    }

    public function store(Request $request)
    {
        $request->validate([
            'title' => 'required|string|max:255',
            'description' => 'nullable|string',
        ]);

        $competency = Competency::create($request->only(['title', 'description']));
        return response()->json($competency, 201);
    }

    public function show(Competency $competency)
    {
        return response()->json($competency);
    }

    public function update(Request $request, Competency $competency)
    {
        $competency->update($request->only(['title', 'description']));
        return response()->json($competency);
    }

    public function destroy(Competency $competency)
    {
        $competency->delete();
        return response()->json(['message' => 'Competency deleted']);
    }
}