class FetcherFactory:
    @staticmethod
    def get_fetcher(market: str, tushare_token: str = None, av_key: str = None, **kwargs):
        from .base import DataFetcher
        market = market.upper()
        if market == 'CN':
            if not tushare_token:
                raise ValueError("Tushare token is required for CN market")
            from .cn_fetcher import CnFetcher
            return CnFetcher(tushare_token)
        if market == 'HK':
            ifind_token = kwargs.get('ifind_refresh_token') or kwargs.get('jquants_refresh_token')
            if not ifind_token:
                 import os
                 ifind_token = os.getenv('IFIND_REFRESH_TOKEN')
            if not ifind_token:
                raise ValueError("iFinD Refresh Token is required for HK market")
            from .hk_fetcher import HkFetcher
            return HkFetcher(ifind_token)
        elif market == 'US':
            if not av_key:
                raise ValueError("Alpha Vantage key is required for US market")
            from .us_fetcher import UsFetcher
            return UsFetcher(av_key)
        elif market == 'JP':
            ifind_token = kwargs.get('ifind_refresh_token') or kwargs.get('jquants_refresh_token')
            if not ifind_token:
                 import os
                 ifind_token = os.getenv('IFIND_REFRESH_TOKEN') or os.getenv('JQUANTS_REFRESH_TOKEN')
            if not ifind_token:
                raise ValueError("iFinD Refresh Token is required for JP market")
            from .jp_fetcher import JpFetcher
            return JpFetcher(ifind_token)
        elif market == 'VN':
            ifind_token = kwargs.get('ifind_refresh_token')
            if not ifind_token:
                 import os
                 ifind_token = os.getenv('IFIND_REFRESH_TOKEN')
            if not ifind_token:
                raise ValueError("iFinD Refresh Token is required for VN market")
            from .vn_fetcher import VnFetcher
            return VnFetcher(ifind_token)
        else:
            raise ValueError(f"Unsupported market: {market}")
