<?php

namespace App\Http\Controllers\admin;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use App\Http\Requests\filesRequest;
use App\Http\Requests\docRequest;
use App\Models\file;
use App\Models\admin;
use LaravelLocalization;
use App\Traits\allTraits;


class caseToUserController extends Controller
{


    public function assignCaseToUser($adminId, $fileId)
    {
        dd($adminId, $fileId);  // تحقق من القيم عند وصولها

        $admin = Admin::findOrFail($adminId);
        $admin->cases()->attach($fileId);

        return redirect()->back()->with(['successAdd' => 'تم تعيين القضية بنجاح']);
    }
    public function AllCaseToUser() {
        $files =  file::All();
        $admins =  admin::All();
        return view('admin.dashboard.caseToUser', compact('files', 'admins'));
    }



    public function editFiles($files_id)
    {

        $files = file::find($files_id);  // search in given table id only
        if (!$files)
            return redirect()->back();
        $files = file::all()->find($files_id);
        return view('admin.dashboard.editFile', compact('files'));

    }



    public function UpdateFiles(filesRequest $request, $files_id)
    {

        $file = file::find($files_id);
        if (!$file)
            return redirect()->back();

        //update data



        $file->update([
            'client_id' => $request -> client_id,
            'attribute_id' => $request -> attribute_id,
            'court_id' => $request -> court_id,
            'police_id' => $request -> police_id,
            'documentation_office_id' => $request -> documentation_office_id,
            'caseNum' => $request -> caseNum,
            'litigationDegree' => $request -> litigationDegree,
            'opponentName' => $request -> opponentName,
            'attorneyType' => $request -> attorneyType,
            'opponentAddress' => $request -> opponentAddress,
            'professorsLawyer' => $request -> professorsLawyer,
            'caseType' => $request -> caseType,
            'details' => $request -> details,
        ]);

        return redirect()->back()->with(['successEdit' => ' تم التحديث بنجاح ']);

    }





}
