<?php

namespace App\Http\Controllers\admin;

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

class QueryController extends Controller
{
    public function store(Request $request)
    {
        $validated = $request->validate([
            'name' => 'required|string|max:255',
            'email' => 'required|string|email|max:255|unique:users',
            'number' => 'nullable|string|max:15',
            'message' => 'nullable|string',
            'user_type' => 'nullable|string|max:50',
        ]);

        $user = Query::create($validated);

        return response()->json($user, 201);
    }

    public function index()
    {
        $users = Query::all();
        return response()->json($users);
    }

    public function show($id)
    {
        $user = Query::findOrFail($id);
        return response()->json($user);
    }
}
