package equipo.once.elizabeth.richard.wilson.controllers.view.inquilino;

import equipo.once.elizabeth.richard.wilson.usecases.DisponibilidadAreaComunUseCase;
import equipo.once.elizabeth.richard.wilson.usecases.dtos.DisponibilidadAreaRequest;
import equipo.once.elizabeth.richard.wilson.usecases.dtos.DisponibilidadAreaResponse;
import equipo.once.elizabeth.richard.wilson.usecases.dtos.SolicitudAreaComunForm;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import javax.servlet.http.HttpSession;

@Controller
@RequestMapping(value = "/inquilino/solicitudes/")
public class SolicitudAreaComunController extends InquilinoController  {

    @Autowired
    private DisponibilidadAreaComunUseCase disponibilidadAreaComunUseCase;
    private ModelAndView modelAndView = new ModelAndView(SOLICITUDES_AREACOMUN_REGISTRAR);
    private static final String SOLICITUD_AREACOMUN_FORM = "solicitudAreaComunForm";
    private static final String SOLICITUDES_AREACOMUN_REGISTRAR = "/inquilino/solicitudes/areacomun/registrar";

    @RequestMapping(value = "areacomun", method = RequestMethod.GET)
    public ModelAndView solicitudesAreaComunGet(){
        modelAndView.clear();

        modelAndView.addObject(SOLICITUD_AREACOMUN_FORM, new SolicitudAreaComunForm());
        return modelAndView;
    }

    @RequestMapping(value = "areacomun",params = {"registrar"}, method = RequestMethod.POST)
    public ModelAndView solicitudesAreaComunPostRegistrar(SolicitudAreaComunForm form , RedirectAttributes redirectAttrs,
                                                 HttpSession httpSession){
        modelAndView.clear();

        return modelAndView;
    }

    @RequestMapping(value = "areacomun",params = {"cancelar"}, method = RequestMethod.POST)
    public ModelAndView solicitudesAreaComunPostCancelar(SolicitudAreaComunForm form , RedirectAttributes redirectAttrs,
                                                 HttpSession httpSession){
        modelAndView.clear();

        return modelAndView;
    }



    @RequestMapping(value = "areacomun",params = {"verificarDisponibilidad"}, method = RequestMethod.POST)
    public ModelAndView solicitudesAreaComunPostVerificar(SolicitudAreaComunForm form ,
                                                          RedirectAttributes redirectAttrs,
                                                         HttpSession httpSession){
        modelAndView.clear();
        DisponibilidadAreaRequest request = DisponibilidadAreaRequest.construirRequest(form);
        disponibilidadAreaComunUseCase.request = request;

        disponibilidadAreaComunUseCase.solicitar();

        DisponibilidadAreaResponse response =
            (DisponibilidadAreaResponse) disponibilidadAreaComunUseCase.obtenerRespuesta();


        form = SolicitudAreaComunForm.construirForm(response);

        modelAndView.addObject(SOLICITUD_AREACOMUN_FORM, form);

        return modelAndView;
    }
}

@@ -1077,61 +1077,10 @@
 iew 
-= new ModelAndView(SOLICITUDES_AREACOMUN_REGISTRAR)
 ;%0A
+
     
@@ -1223,25 +1223,24 @@
 EGISTRAR = %22
-/
 inquilino/so
@@ -1408,35 +1408,78 @@
 modelAndView
-.clear(
+ = new ModelAndView(SOLICITUDES_AREACOMUN_REGISTRAR
 );%0A
-%0A
         mode
@@ -1892,39 +1892,83 @@
     modelAndView
-.clear(
+ = new ModelAndView(SOLICITUDES_AREACOMUN_REGISTRAR
 );%0A%0A        retu
@@ -2303,19 +2303,62 @@
 View
-.clear(
+ = new ModelAndView(SOLICITUDES_AREACOMUN_REGISTRAR
 );%0A
-%0A
     
@@ -2785,15 +2785,59 @@
 View
-.clear(
+ = new ModelAndView(SOLICITUDES_AREACOMUN_REGISTRAR
 );%0A 

fix llamada a clear.