import viktor as vkt


class Parametrization(vkt.Parametrization):
    geometry = vkt.Tab("Geometry")
    geometry.slab = vkt.Section("Slab")
    geometry.slab.width_x = vkt.NumberField("Width in x", suffix="mm", default=6000)
    geometry.slab.width_y = vkt.NumberField("Width in y", suffix="mm", default=5000)
    geometry.slab.thickness = vkt.NumberField("Thickness", suffix="mm", default=500)

    geometry.piles = vkt.Section("Piles")
    geometry.piles.diameter = vkt.NumberField("Diameter", suffix="mm", default=500)
    geometry.piles.length = vkt.NumberField("Length", suffix="m", default=7)

    loads = vkt.Tab("Loads")
    loads.input = vkt.Section("Input")
    loads.input.uniform_load = vkt.NumberField("Uniform load", suffix="kN/m2", default=1)

    scia = vkt.Tab("SCIA")
    scia.downloads = vkt.Section("Downloads")
    scia.downloads.input_xml_btn = vkt.DownloadButton("Input .xml", method="download_scia_input_xml")
    scia.downloads.input_def_btn = vkt.DownloadButton("Input .def", method="download_scia_input_def")
    scia.downloads.input_esa_btn = vkt.DownloadButton("Input .esa", method="download_scia_input_esa")


class Foundation(vkt.Controller):
    parametrization = Parametrization

    @vkt.GeometryView("3D", x_axis_to_right=True)
    def visualize(self, params, **kwargs):
        scia_model = self.create_scia_model(params)
        geometries = self.create_visualization_geometries(params, scia_model)
        return vkt.GeometryResult(geometries)

    def download_scia_input_esa(self, params, **kwargs):
        return vkt.DownloadResult()

    def download_scia_input_def(self, params, **kwargs):
        return vkt.DownloadResult()

    def download_scia_input_xml(self, params, **kwargs):
        return vkt.DownloadResult()

    def create_scia_model(self, params) -> vkt.scia.Model:
        # The SCIA model is created here
        model = vkt.scia.Model()
        return model

    def create_visualization_geometries(self, params, scia_model):
        # The SCIA model is converted to VIKTOR geometry here
        geometries = []
        return geometries


initial_entities = [
    vkt.InitialEntity("Foundation", "Example")
]
