from app.merchant.accessor.merchant_product_accessor import MerchantProductAccessor


class MerchantProduct:
    def __init__(self, merchant_product):
        self.merchant_product = merchant_product

    @classmethod
    def get_product(cls, merchant_id, product_id):
        return MerchantProductAccessor.get_merchant_product(merchant_id, product_id)

    @classmethod
    def get_merchant_products(cls, merchant_id, center_id):
        return MerchantProductAccessor.get_merchant_products(merchant_id, center_id)

    @classmethod
    def get_all_serialized(cls, merchant_products):
        serialized = []
        for merchant_product in merchant_products:
            serialized.append(MerchantProduct(merchant_product).get_serialized())

        return serialized

    def get_serialized(self):
        return {
            "id": self.merchant_product.id,
            "name": self.merchant_product.name
        }
