<?php

namespace App\Http\Controllers\Admin;

use App\Models\UnlockOrder;
use Illuminate\Http\Request;
use Inertia\Inertia;

class AdminUnlockOrderController extends Controller
{
    public function index()
    {
        $orders = UnlockOrder::with('business')->latest()->get();

        return Inertia::render('Admin/UnlockOrders/Index', [
            'orders' => $orders,
        ]);
    }

    public function show(UnlockOrder $order)
    {
        return Inertia::render('Admin/UnlockOrders/Show', [
            'order' => $order->load('business'),
        ]);
    }

    public function updateStatus(Request $request, UnlockOrder $order)
    {
        $request->validate([
            'status' => 'required|in:pending,in_progress,done',
        ]);

        $order->update(['status' => $request->status]);

        return redirect()->back();
    }

    public function addNote(Request $request, UnlockOrder $order)
    {
        $request->validate([
            'note' => 'required|string',
        ]);

        $order->update(['note' => $request->note]);

        return redirect()->back();
    }
}