<?php
namespace Incoviba\Controller\Inmobiliarias;

use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Incoviba\Common\Implement\Exception\EmptyResult;
use Incoviba\Common\Alias\View;
use Incoviba\Repository;
use Incoviba\Service;

class Proveedores
{
    public function __invoke(ServerRequestInterface $request, ResponseInterface $response, View $view,
                             Service\Sociedad $sociedadService,
                             Repository\Inmobiliaria\TipoSociedad $tipoSociedad): ResponseInterface
    {
        $sociedades = [];
        try {
            $sociedades = $sociedadService->getAll('nombre');
        } catch (EmptyResult) {}
        $tiposSociedades = [];
        try {
            $tiposSociedades = $tipoSociedad->fetchAll('descripcion');
        } catch (EmptyResult) {}
        return $view->render($response, 'inmobiliarias.proveedores', compact('sociedades', 'tiposSociedades'));
    }
}
