<?php namespace App\Http\Controllers; use Illuminate\Http\Request; use App\Models\{Department,Office,Shift,Client,Holiday,ExpenseCategory,LeaveType,Asset,PerformanceCycle}; class AdminResourceController extends Controller {private array $map=['departments'=>Department::class,'offices'=>Office::class,'shifts'=>Shift::class,'clients'=>Client::class,'holidays'=>Holiday::class,'expense-categories'=>ExpenseCategory::class,'leave-types'=>LeaveType::class,'assets'=>Asset::class,'performance-cycles'=>PerformanceCycle::class]; private array $rules=['departments'=>['name'=>'required|string|max:120','code'=>'required|string|max:30'],'offices'=>['name'=>'required|string|max:120','code'=>'required|string|max:30','address'=>'nullable|string','timezone'=>'required|string|max:80'],'shifts'=>['name'=>'required|string|max:120','start_time'=>'required','end_time'=>'required','late_grace_minutes'=>'nullable|integer|min:0','early_checkout_grace_minutes'=>'nullable|integer|min:0','minimum_work_minutes'=>'nullable|integer|min:0','overtime_after_minutes'=>'nullable|integer|min:0'],'clients'=>['name'=>'required|string|max:160','company'=>'nullable|string|max:160','status'=>'required|string|max:40'],'holidays'=>['name'=>'required|string|max:160','holiday_date'=>'required|date','is_paid'=>'nullable|boolean'],'expense-categories'=>['name'=>'required|string|max:120','code'=>'required|string|max:30','requires_founder_approval'=>'nullable|boolean','is_active'=>'nullable|boolean'],'leave-types'=>['name'=>'required|string|max:120','code'=>'required|string|max:30','worker_type'=>'required|in:all,employee,intern','annual_days'=>'required|numeric|min:0','is_paid'=>'nullable|boolean','is_active'=>'nullable|boolean'],'assets'=>['asset_code'=>'required|string|max:80','type'=>'required|string|max:80','make_model'=>'nullable|string|max:160','serial_number'=>'nullable|string|max:160','status'=>'required|string|max:40','condition'=>'nullable|string|max:80'],'performance-cycles'=>['name'=>'required|string|max:160','start_date'=>'required|date','end_date'=>'required|date|after_or_equal:start_date','status'=>'required|string|max:40']]; private function cls($r){abort_unless(isset($this->map[$r]),404);return $this->map[$r];} public function index(string $resource){$c=$this->cls($resource);return view('admin.resources',['resource'=>$resource,'rows'=>$c::latest()->paginate(25),'rules'=>array_keys($this->rules[$resource])]);} public function store(Request $r,string $resource){$c=$this->cls($resource);$d=$r->validate($this->rules[$resource]);foreach(['is_paid','is_active','requires_founder_approval'] as $b)if(array_key_exists($b,$this->rules[$resource]))$d[$b]=$r->boolean($b);$c::create($d);return back()->with('success','Record created.');} public function update(Request $r,string $resource,int $id){$c=$this->cls($resource);$row=$c::findOrFail($id);$d=$r->validate($this->rules[$resource]);foreach(['is_paid','is_active','requires_founder_approval'] as $b)if(array_key_exists($b,$this->rules[$resource]))$d[$b]=$r->boolean($b);$row->update($d);return back()->with('success','Record updated.');} public function destroy(string $resource,int $id){$c=$this->cls($resource);$c::findOrFail($id)->delete();return back()->with('success','Record deleted.');}}