from app.merchant.accessor.merchant_accessor import MerchantAccessor
from app.merchant.merchant_center import MerchantCenter
from app.merchant.merchant_product import MerchantProduct


class Merchant:
    def __init__(self, merchant):
        self.merchant = merchant

    def get_center(self, center_id):
        return MerchantCenter.get_center(self.get_merchant_id(), center_id)

    def get_product(self, product_id):
        return MerchantProduct.get_product(self.get_merchant_id(), product_id)

    def get_merchant_id(self):
        return self.merchant.id

    @classmethod
    def get_all_serialized(cls, merchants):
        serialized = []
        for merchant in merchants:
            serialized.append(Merchant(merchant).get_serialized())

        return serialized

    def get_serialized(self):
        return {
            "id": self.get_merchant_id(),
            "name": self.merchant.merchant_name
        }

    @classmethod
    def get_all_merchants(cls, client_id, client_secret):
        return MerchantAccessor.get_all_merchants(client_id, client_secret)

    @classmethod
    def get_merchant(cls, merchant_id):
        return MerchantAccessor.get_merchant(merchant_id)

    @classmethod
    def get_merchant_by_slug(cls, merchant_slug):
        return MerchantAccessor.get_merchant_by_slug(merchant_slug)

    @classmethod
    def get_merchant_location(cls, merchant_id):
        return MerchantAccessor.get_merchant_location(merchant_id)

    def get_gst_number(self):
        return self.merchant.gst_number

    def get_slug(self):
        return self.merchant.slug

    @classmethod
    def has_merchant_location_bank(cls, location_id):
        return MerchantAccessor.has_merchant_location_bank(location_id)

    def get_merchant_name(self):
        return self.merchant.merchant_name

    def get_merchant_logo(self):
        return self.merchant.merchant_logo
