# -*- coding: utf-8 -*-

from tools import trace, timer

from Model.Except import NotImplementedMethodeError
from Model.Tools.PamhyrList import PamhyrModelList
from Model.SedimentLayer.SedimentLayer import SedimentLayer


class SedimentLayerList(PamhyrModelList):
    _sub_classes = [SedimentLayer]

    @classmethod
    def _sql_load(cls, execute, data=None):
        new = cls(status=data["status"])

        new._lst = SedimentLayer._sql_load(execute, data)

        return new

    def _sql_save(self, execute, data=None):
        ok = True

        # Delete previous data
        execute("DELETE FROM sedimentary_layer")
        execute("DELETE FROM sedimentary_layer_layer")

        for sl in self._lst:
            ok &= sl._sql_save(execute, data)

        return ok

    @property
    def sediment_layers(self):
        return self.lst

    def new(self, index):
        n = SedimentLayer(status=self._status)
        self.insert(index, n)
        self._status.modified()
        return n
