<?php

namespace App\Http\Controllers\Admin;

use App\Http\Controllers\Controller;
use App\Models\IdDocument;
use Illuminate\Http\Request;

class IdDocumentController extends Controller
{

    public function index()
    {
        $idDocuments = IdDocument::with('user')->get(); // Load user with documents

        return response()->json($idDocuments);
    }


    // Function to verify an ID document
    public function verify(Request $request, $id)
    {
        $request->validate([
            'verified' => 'required|boolean',
        ]);

        try {
            $idDocument = IdDocument::findOrFail($id);
            $idDocument->verified = $request->verified;
            $idDocument->save();

            return response()->json([
                'message' => 'Document verification status updated successfully.',
                'verified' => $idDocument->verified,
            ]);
        } catch (\Exception $e) {
            return response()->json([
                'message' => 'Error updating verification status.',
                'error' => $e->getMessage(),
            ], 500);
        }
    }
}