from app.service.design_fast.pipeline import LoadImage, KeyPoint, Segmentation, Color, PrintPainting, Scaling, Split, LoadBodyImage, ContourDetection


class BaseItem:
    def __init__(self, data, basic):
        self.result = data.copy()
        self.result['name'] = data['type'].lower()
        self.result.pop("type")
        self.result.update(basic)


class OthersItem(BaseItem):
    def __init__(self, data, basic, minio_client):
        super().__init__(data, basic)
        self.Others_pipeline = [
            LoadImage(minio_client),
            # KeyPoint(),
            ContourDetection(),
            # Segmentation(minio_client),
            # BackPerspective(minio_client),
            Color(minio_client),
            PrintPainting(minio_client),
            Scaling(),
            Split(minio_client)
        ]

    def process(self):
        for item in self.Others_pipeline:
            self.result = item(self.result)
        return self.result


class TopItem(BaseItem):
    def __init__(self, data, basic, minio_client):
        super().__init__(data, basic)
        self.top_pipeline = [
            LoadImage(minio_client),
            KeyPoint(),
            Segmentation(minio_client),
            # BackPerspective(minio_client),
            Color(minio_client),
            PrintPainting(minio_client),
            Scaling(),
            Split(minio_client)
        ]

    def process(self):
        for item in self.top_pipeline:
            self.result = item(self.result)
        return self.result


class BottomItem(BaseItem):
    def __init__(self, data, basic, minio_client):
        super().__init__(data, basic)
        self.bottom_pipeline = [
            LoadImage(minio_client),
            KeyPoint(),
            ContourDetection(),
            Segmentation(minio_client),
            # BackPerspective(minio_client),
            Color(minio_client),
            PrintPainting(minio_client),
            Scaling(),
            Split(minio_client)
        ]

    def process(self):
        for item in self.bottom_pipeline:
            self.result = item(self.result)
        return self.result


class BodyItem(BaseItem):
    def __init__(self, data, basic, minio_client):
        super().__init__(data, basic)
        self.top_pipeline = [
            LoadBodyImage(minio_client),
        ]

    def process(self):
        for item in self.top_pipeline:
            self.result = item(self.result)
        return self.result
