<?php

namespace App\Http\Controllers;

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

class VersionController extends Controller
{
    public function index()
    {
        return Version::all();
    }

    public function store(Request $request)
    {
        $request->validate([
            'job_id' => 'required|exists:jobs,id',
            'version_number' => 'required|string',
            'notes' => 'nullable|string',
        ]);

        $version = Version::create($request->all());
        return response()->json($version, 201);
    }

    public function show(Version $version)
    {
        return response()->json($version);
    }

    public function update(Request $request, Version $version)
    {
        $version->update($request->all());
        return response()->json($version);
    }

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