"""表名生成。每个函数对应一类表。

加新表：加一个函数。改命名规则：只改对应函数。
"""

# ============== 周期 syn 状态表 ==============
def all_syn_st_day(site, date_str):
    """all_syn_st_day('us', '2026-02-15') -> us_all_syn_st_day_2026_02_15"""
    return f"{site}_all_syn_st_day_{_norm(date_str)}"

def all_syn_st_month(site, year_month):
    """all_syn_st_month('us', '2026-02') -> us_all_syn_st_month_2026_02"""
    return f"{site}_all_syn_st_month_{_norm(year_month)}"

def all_syn_st_week(site, year_week):
    """all_syn_st_week('us', '2026_w07') -> us_all_syn_st_week_2026_w07"""
    return f"{site}_all_syn_st_week_{year_week}"

def chatgpt_syn_st(site):
    return f"{site}_chatgpt_syn_st"


# ============== 周期 detail 表 ==============
def asin_detail_day(site, year):
    return f"{site}_asin_detail_day_{year}"

def asin_detail_month(site, year, month):
    """asin_detail_month('us', 2026, 2) -> us_asin_detail_month_2026_02"""
    return f"{site}_asin_detail_month_{year}_{int(month):02d}"


# ============== merchantwords 系列 ==============
def merchantwords_syn(site, date_str):
    return f"{site}_merchantwords_syn_{_norm(date_str)}"

def merchantwords(site, date_str):
    return f"{site}_merchantwords_{_norm(date_str)}"

def merchantwords_asin_detail(site, report_info):
    return f"{site}_merchantwords_asin_detail_{report_info}"


# ============== 静态站点表 ==============
def cookies(site):                  return f"{site}_cookies"
def comment_cookies(site):          return f"{site}_comment_cookies"
def asin_detail(site):              return f"{site}_asin_detail"
def bs_category(site):              return f"{site}_bs_category"
def bs_category_detail(site):       return f"{site}_bs_category_detail"
def one_category_report(site):      return f"{site}_one_category_report"
def user_seller_collections(site):  return f"{site}_user_seller_collections"
def search_term_rank_type(site):    return f"{site}_search_term_rank_type"


# ============== helper ==============
def _norm(s):
    """'2026-02-15' / '2026-02' → '2026_02_15' / '2026_02'"""
    return str(s).replace('-', '_')


# ============== 自测 ==============
if __name__ == "__main__":
    checks = [
        (all_syn_st_day("us", "2026-02-15"),      "us_all_syn_st_day_2026_02_15"),
        (all_syn_st_month("uk", "2026-02"),       "uk_all_syn_st_month_2026_02"),
        (all_syn_st_week("de", "2026_w07"),       "de_all_syn_st_week_2026_w07"),
        (chatgpt_syn_st("us"),                    "us_chatgpt_syn_st"),
        (asin_detail_day("us", 2026),             "us_asin_detail_day_2026"),
        (asin_detail_month("us", 2026, 2),        "us_asin_detail_month_2026_02"),
        (asin_detail_month("us", 2026, "9"),      "us_asin_detail_month_2026_09"),
        (asin_detail_month("us", 2026, 12),       "us_asin_detail_month_2026_12"),
        (merchantwords_syn("us", "2026-02"),      "us_merchantwords_syn_2026_02"),
        (merchantwords("us", "2026-02"),          "us_merchantwords_2026_02"),
        (merchantwords_asin_detail("us", "2026_02"), "us_merchantwords_asin_detail_2026_02"),
        (cookies("us"),                           "us_cookies"),
        (comment_cookies("uk"),                   "uk_comment_cookies"),
        (asin_detail("de"),                       "de_asin_detail"),
        (bs_category("fr"),                       "fr_bs_category"),
        (bs_category_detail("es"),                "es_bs_category_detail"),
        (one_category_report("it"),               "it_one_category_report"),
        (user_seller_collections("us"),           "us_user_seller_collections"),
        (search_term_rank_type("us"),             "us_search_term_rank_type"),
    ]
    failed = [(got, want) for got, want in checks if got != want]
    if failed:
        for got, want in failed:
            print(f"FAIL: got={got!r} want={want!r}")
        raise SystemExit(1)
    print(f"OK: {len(checks)} cases passed")
