import pytest
from hypothesis import given
from hypothesis import strategies as st

from suno_utils.worker.detect_artist_name import (
    BLOCKED_ARTISTS,
    extract_artist_name_from_text,
    prep_text,
)


@pytest.mark.parametrize(
    "input_text, expected_output", [("foo", "foo"), ("   FOO   ", "foo"), ("\u200bbbno$", "bbno$")]
)
def test_prep_text(input_text, expected_output):
    assert expected_output == prep_text(input_text)


def test_BLOCKED_ARTISTS():
    assert min(map(len, BLOCKED_ARTISTS)) >= 3


@pytest.mark.parametrize(
    "input_text, expected_output",
    [
        ("Text with Beyoncé, which contains an accented char", "beyonce"),
        ("Text with Beyonce in it", "beyonce"),
        ("Text with beyonce in it", "beyonce"),
        ("No artist name here", None),
        ("text with THE ROLLING STONES", "the rolling stones"),
        ("Partial match CVS should not match", None),
        ("DJ Snake and Lady Gaga", "dj snake"),  # Assuming function returns the first match
        ("LADY GAGA", "lady gaga"),
        ("Lady Gaga", "lady gaga"),
        ("lady gaga", "lady gaga"),
        ("JAPA", "japa"),
        ("2pac", "2pac"),
        ("aerosmith", "aerosmith"),
        ("alice cooper", "alice cooper"),
        ("alison krauss", "alison krauss"),
        ("the allman brothers band", "the allman brothers band"),
        ("amy winehouse", "amy winehouse"),
        ("andre rieu", "andre rieu"),
        ("andrea bocelli", "andrea bocelli"),
        ("antonio carlos jobim", "antonio carlos jobim"),
        ("arcade fire", "arcade fire"),
        ("ariana grande", "ariana grande"),
        ("audioslave", "audioslave"),
        ("beastie boys", "beastie boys"),
        ("the beatles", "the beatles"),
        ("bee gees", "bee gees"),
        ("belinda carlisle", "belinda carlisle"),
        ("ben harper", "ben harper"),
        ("billie eilish", "billie eilish"),
        ("billie holiday", "billie holiday"),
        ("billy currington", "billy currington"),
        ("black eyed peas", "black eyed peas"),
        ("black sabbath", "black sabbath"),
        ("blondie", "blondie"),
        ("bob dylan", "bob dylan"),
        ("bob marley", "bob marley"),
        ("bob seger", "bob seger"),
        ("bon jovi", "bon jovi"),
        ("bonnie raitt", "bonnie raitt"),
        ("boyz ii men", "boyz ii men"),
        ("brantley gilbert", "brantley gilbert"),
        ("bruce springsteen", "bruce springsteen"),
        ("bryan adams", "bryan adams"),
        ("bryan ferry", "bryan ferry"),
        ("carrie underwood", "carrie underwood"),
        ("cher", "cher"),
        ("chris cornell", "chris cornell"),
        ("chris stapleton", "chris stapleton"),
        ("chuck berry", "chuck berry"),
        ("the clash", "the clash"),
        ("commodores", "commodores"),
        ("corinne bailey rae", "corinne bailey rae"),
        ("counting crows", "counting crows"),
        ("the cranberries", "the cranberries"),
        ("creedence clearwater revival", "creedence clearwater revival"),
        ("crowded house", "crowded house"),
        ("david bowie", "david bowie"),
        ("debarge", "debarge"),
        ("def leppard", "def leppard"),
        ("demi lovato", "demi lovato"),
        ("demis roussos", "demis roussos"),
        ("diana krall", "diana krall"),
        ("diana ross", "diana ross"),
        ("dierks bentley", "dierks bentley"),
        ("dire straits", "dire straits"),
        ("don henley", "don henley"),
        ("donna summer", "donna summer"),
        ("dr dre", "dr dre"),
        ("eels", None),
        ("ella fitzgerald", "ella fitzgerald"),
        ("elton john", "elton john"),
        ("elvis presley", "elvis presley"),
        ("eminem", "eminem"),
        ("eric clapton", "eric clapton"),
        ("etta james", "etta james"),
        ("fergie", "fergie"),
        ("fleetwood mac", "fleetwood mac"),
        ("foo fighters", "foo fighters"),
        ("foxy brown", "foxy brown"),
        ("frank sinatra", "frank sinatra"),
        ("frank zappa", "frank zappa"),
        ("freddie mercury", "freddie mercury"),
        ("gang starr", "gang starr"),
        ("george benson", "george benson"),
        ("george strait", "george strait"),
        ("george thorogood", "george thorogood"),
        ("glen campbell", "glen campbell"),
        ("gregory isaacs", "gregory isaacs"),
        ("gregory porter", "gregory porter"),
        ("gwen stefani", "gwen stefani"),
        ("halsey", "halsey"),
        ("herbie hancock", "herbie hancock"),
        ("hoobastank", "hoobastank"),
        ("inxs", "inxs"),
        ("ice cube", "ice cube"),
        ("iggy pop", "iggy pop"),
        ("iron maiden", "iron maiden"),
        ("isaac hayes", "isaac hayes"),
        ("the isley brothers", "the isley brothers"),
        ("jacques brel", "jacques brel"),
        ("jadakiss", "jadakiss"),
        ("james morrison", "james morrison"),
        ("janet jackson", "janet jackson"),
        ("jeezy", "jeezy"),
        ("jessie j", "jessie j"),
        ("jimi hendrix", "jimi hendrix"),
        ("jimmy buffett", "jimmy buffett"),
        ("jimmy cliff", "jimmy cliff"),
        ("joe cocker", "joe cocker"),
        ("john coltrane", "john coltrane"),
        ("john fogerty", "john fogerty"),
        ("john lee hooker", "john lee hooker"),
        ("john lennon", "john lennon"),
        ("john mellencamp", "john mellencamp"),
        ("johnny gill", "johnny gill"),
        ("joni mitchell", "joni mitchell"),
        ("jonny lang", "jonny lang"),
        ("joss stone", "joss stone"),
        ("justin bieber", "justin bieber"),
        ("kacey musgraves", "kacey musgraves"),
        ("kaiser chiefs", "kaiser chiefs"),
        ("katy perry", "katy perry"),
        ("keane", "keane"),
        ("kendrick lamar", "kendrick lamar"),
        ("the killers", "the killers"),
        ("the kinks", "the kinks"),
        ("kip moore", "kip moore"),
        ("the kooks", "the kooks"),
        ("lady gaga", "lady gaga"),
        ("lana del rey", "lana del rey"),
        ("led zeppelin", "led zeppelin"),
        ("lenny kravitz", "lenny kravitz"),
        ("lil wayne", "lil wayne"),
        ("lionel richie", "lionel richie"),
        ("lorde", "lorde"),
        ("louis armstrong", "louis armstrong"),
        ("ludacris", "ludacris"),
        ("ludovico einaudi", "ludovico einaudi"),
        ("luke bryan", "luke bryan"),
        ("the lumineers", "the lumineers"),
        ("lynyrd skynyrd", "lynyrd skynyrd"),
        ("marilyn manson", "marilyn manson"),
        ("mark knopfler", "mark knopfler"),
        ("maroon 5", "maroon 5"),
        ("marvin gaye", "marvin gaye"),
        ("the mavericks", "the mavericks"),
        ("maxi priest", "maxi priest"),
        ("meat loaf", "meat loaf"),
        ("megadeth", "megadeth"),
        ("melody gardot", "melody gardot"),
        ("metallica", "metallica"),
        ("michael kiwanuka", "michael kiwanuka"),
        ("mike oldfield", "mike oldfield"),
        ("the moody blues", "the moody blues"),
        ("nat king cole", "nat king cole"),
        ("neil diamond", "neil diamond"),
        ("nicki minaj", "nicki minaj"),
        ("nina simone", "nina simone"),
        ("nine inch nails", "nine inch nails"),
        ("norah jones", "norah jones"),
        ("onerepublic", "onerepublic"),
        ("otis redding", "otis redding"),
        ("pj harvey", "pj harvey"),
        ("papa roach", "papa roach"),
        ("pat benatar", "pat benatar"),
        ("pato banton", "pato banton"),
        ("patsy cline", "patsy cline"),
        ("pearl jam", "pearl jam"),
        ("peter frampton", "peter frampton"),
        ("phil collins", "phil collins"),
        ("pink floyd", "pink floyd"),
        ("portishead", "portishead"),
        ("queens of the stone age", "queens of the stone age"),
        ("quincy jones", "quincy jones"),
        ("rammstein", "rammstein"),
        ("reba mcentire", "reba mcentire"),
        ("red hot chili peppers", "red hot chili peppers"),
        ("redman", "redman"),
        ("rihanna", "rihanna"),
        ("ringo starr", "ringo starr"),
        ("rob zombie", "rob zombie"),
        ("robbie williams", "robbie williams"),
        ("robert glasper", "robert glasper"),
        ("robert palmer", "robert palmer"),
        ("rod stewart", "rod stewart"),
        ("the rolling stones", "the rolling stones"),
        ("roxy music", "roxy music"),
        ("roy orbison", "roy orbison"),
        ("rufus wainwright", "rufus wainwright"),
        ("sam cooke", "sam cooke"),
        ("sammy hagar", "sammy hagar"),
        ("scorpions", "scorpions"),
        ("selena gomez", "selena gomez"),
        ("sergio mendes", "sergio mendes"),
        ("sex pistols", "sex pistols"),
        ("shania twain", "shania twain"),
        ("sheryl crow", "sheryl crow"),
        ("slick rick", "slick rick"),
        ("the smashing pumpkins", "the smashing pumpkins"),
        ("smokey robinson", "smokey robinson"),
        ("snoop dogg", "snoop dogg"),
        ("sonic youth", "sonic youth"),
        ("soundgarden", "soundgarden"),
        ("spandau ballet", "spandau ballet"),
        ("spice girls", "spice girls"),
        ("steely dan", "steely dan"),
        ("stereophonics", "stereophonics"),
        ("steve earle", "steve earle"),
        ("steve winwood", "steve winwood"),
        ("steven tyler", "steven tyler"),
        ("stevie wonder", "stevie wonder"),
        ("suzanne vega", "suzanne vega"),
        ("tears for fears", "tears for fears"),
        ("teena marie", "teena marie"),
        ("the temptations", "the temptations"),
        ("tesla", None),
        ("thomas rhett", "thomas rhett"),
        ("tim mcgraw", "tim mcgraw"),
        ("toby keith", "toby keith"),
        ("tom waits", "tom waits"),
        ("tori amos", "tori amos"),
        ("the tragically hip", "the tragically hip"),
        ("traveling wilburys", "traveling wilburys"),
        ("ub40", "ub40"),
        ("vangelis", "vangelis"),
        ("the velvet underground", "the velvet underground"),
        ("the verve", "the verve"),
        ("vince gill", "vince gill"),
        ("the weeknd", "the weeknd"),
        ("weezer", "weezer"),
        ("whitesnake", "whitesnake"),
        ("willie nelson", "willie nelson"),
        ("wolfmother", "wolfmother"),
        ("yeah yeah yeahs", "yeah yeah yeahs"),
        ("yello", "yello"),
        ("zucchero", "zucchero"),
        ("japanese", None),
        ("hanfu", None),  # don't match 'nf'
        ("evening", None),
        ("porta", None),
        ("ai", None),
        ("AI", None),
        ("a1", None),
        ("ak", None),
        ("rm", None),
        ("portable record player", None),
        (
            (
                "a catchy upbeat song about about the importance of going direct "
                "with your communications and not overly relying on middle men to carry your message"
            ),
            None,
        ),
        ("A euphoric future bass song about life", None),
        ("this", None),
        ("treasure", None),
        ("嘿人李逵", None),
        ("whybaby?", "whybaby?"),
        ("bbno$", "bbno$"),
        ("hank williams jr", "hank williams jr"),
        ("$atori zoom", "$atori zoom"),
        ("장재훈", None),
        ("BTs a", "bts"),
        ("BT s", None),
        ("taylor swaft", "taylor"),
        ("tylor swift", "swift"),
        ("why steely dan why", "steely dan"),
        ("christmas eve", None),
        ("she's a jar, with a heavy lid", None),
        ("two friends", None),
        ("walls", None),
        ("lofi hip hop", None),
        ("lo fi hip hop", None),
        ("lo-fi hip hop", None),
        ("nazareth", None),
        ("sputnik", None),
        ("周杰伦", "zhou jie lun"),
        ("freestyle", None),
        ("michael jackson", "michael jackson"),
        ("avant-garde", None),
        ("Sabrina Carpenter", "sabrina carpenter"),
        ("Miley Cyrus", "miley cyrus"),
    ],
)
def test_extract_artist_name_from_text(input_text, expected_output):
    assert extract_artist_name_from_text(input_text) == expected_output


# during development, consider using: @settings(max_examples=10_000)
@given(st.one_of(st.text(), st.sampled_from(list(BLOCKED_ARTISTS))))
def test_extract_artist_name_from_text_hypothesis(input_text):
    result = extract_artist_name_from_text(input_text)
    if result:
        assert result in BLOCKED_ARTISTS
    else:
        assert input_text not in BLOCKED_ARTISTS
