<?php

namespace Src\Modules\Auth\Laravel\Controllers;

use App\Providers\AppServiceProvider;
use Illuminate\Support\Facades\View;
use Illuminate\Http\Request;
use Src\Modules\Auth\Interfaces\IFactory as IModuleFactory;

class AdminsListController {

    private IModuleFactory $moduleFactory;
    
    public function __construct()
    {
        View::addLocation(__DIR__ . '/../views');
        $this->moduleFactory = app()->get(AppServiceProvider::ADMIN_MODULES)->getAuthFactory();
    }

    public function list()
    {
        $page = $this->moduleFactory->getPagesFactory()->getAdminFactory()->createAdminsListPage();
        return view('admin.adminsList', ['page' => $page]);
    }

    public function delete(Request $request)
    {
        $adminId = $request->get('admin-id') ?? 0;
        $domain = $this->moduleFactory->getApplicationFactory()->getAdminFactory()->getDomain();
        $domain->delete($adminId);
        return redirect()->back();
    }
}