<?php

namespace App\Http\Controllers\Admin;

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

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

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

    public function show(UnlockOrder $order)
    {
        $order->load('shopUser');

        return Inertia::render('Admin/Pages/UnlockOrders/Show', [
            'order' => $order,
        ]);
    }

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

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

        return redirect()->back()->with('success', 'Order status updated!');
    }

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

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

        return redirect()->back()->with('success', 'Note added!');
    }
}
