<?php

// app/Http/Controllers/LabelController.php
namespace App\Http\Controllers;

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

class LabelController extends Controller
{
    public function store(Request $request)
    {
        $request->validate([
            'name' => 'required|string|max:255',
            'color' => 'required|string|max:7',
        ]);

        Label::create($request->only('name', 'color'));
        return redirect()->route('projects.index')->with('success', 'Label created successfully.');
    }

    public function update(Request $request, Label $label)
    {
        $request->validate([
            'name' => 'required|string|max:255',
            'color' => 'required|string|max:7',
        ]);

        $label->update($request->only('name', 'color'));
        return redirect()->route('projects.index')->with('success', 'Label updated successfully.');
    }

    public function destroy(Label $label)
    {
        $label->delete();
        return redirect()->route('projects.index')->with('success', 'Label deleted successfully.');
    }
}
