"""
Process using an application/geo+json and 'image/tiff; application=geotiff' output. Used to test UI interactions.

Author: Trevor James Smith
"""
from pathlib import Path
from pywps import Process, ComplexOutput, ComplexInput
from pywps import FORMATS
from pywps.validator.mode import MODE
import logging


LOGGER = logging.getLogger("PYWPS")

__all__ = ["GeoData"]

DATA_DIR = Path(__file__).parent.parent.joinpath('data')


class GeoData(Process):
    def __init__(self):
        inputs = [ComplexInput("shape",
                               "Geometry",
                               supported_formats=[FORMATS.GEOJSON],
                               mode=MODE.NONE,  # Can be upgraded to STRICT once pywps releases 4.4.3 or 4.5.
                               min_occurs=1,
                               max_occurs=1)
                  ]
        outputs = [
            ComplexOutput(
                "raster",
                "DEM of region in GeoTIFF format.",
                abstract="Elevation data for Olympus Martian region in byte range.",
                as_reference=True,
                supported_formats=[FORMATS.GEOTIFF],
            ),
            ComplexOutput(
                "vector",
                "Region definition in GeoJSON format",
                abstract="Rough vector polygon of the Olympus Mons plateau.",
                as_reference=True,
                supported_formats=[FORMATS.GEOJSON],
            ),
        ]

        super(GeoData, self).__init__(
            self._handler,
            identifier="geodata",
            title="deliver vector and raster data",
            abstract="Return an example raster and vector dataset",
            version="1.0",
            inputs=inputs,
            outputs=outputs,
            store_supported=True,
            status_supported=True,
        )

    @staticmethod
    def _handler(request, response):
        import json
        response.update_status("PyWPS Process started.", 0)

        json.loads(request.inputs["shape"][0].data)

        response.outputs['vector'].file = DATA_DIR / "Olympus_Mons.geojson"

        response.outputs['raster'].file = DATA_DIR / "Olympus.tif"

        response.update_status("PyWPS Process completed.", 100)

        return response

@@ -774,17 +774,17 @@
 _occurs=
-1
+0
 ,%0A      
@@ -1970,24 +1970,109 @@
 rted.%22, 0)%0A%0A
+        if %22shape%22 in request.inputs:%0A            LOGGER.info(%22Loading %60shape%60%22)%0A    
         json

make geodata shape input optional