from aidso_geo.utils import bh_utils


def qianwen_android_process_taobao_eco(data,eco_list):
    eco_result = []
    task_id = data.get('taskId')
    platform = data.get('platform')
    req_id = data.get('reqId')
    prompt = data.get('prompt')
    for index, item in enumerate(eco_list):
        if item.get('card_type') =='single_product':
            raw_data = {
                "eco_id": item.get('item_id', ''),
                "eco_url": item.get('auctionURL', '') or item.get('jump_url',''),
                "eco_title": item.get('title', ''),
                "eco_index": index+1,
                "eco_pic": item.get('pic_path', ''),
                "eco_price": item.get('price', ''),
                "eco_source": 'taobao',
                "platform": platform,
                "task_id": task_id,
                "req_id": req_id,
                "prompt": prompt
            }
            eco_result.append(raw_data)

    return eco_result

def qianwen_android_process_damai_eco(data,eco_list):
    eco_result = []
    task_id = data.get('taskId')
    platform = data.get('platform')
    req_id = data.get('reqId')
    prompt = data.get('prompt')
    for index, item in enumerate(eco_list):
        raw_data = {
            "eco_id": item.get('id', ''),
            "eco_url": item.get('webURL', '') ,
            "eco_title": item.get('name', ''),
            "eco_index": index+1,
            "eco_pic": item.get('verticalPic', ''),
            "eco_price": item.get('priceShowText', ''),
            "eco_source": 'damai',
            "platform": platform,
            "task_id": task_id,
            "req_id": req_id,
            "prompt": prompt
        }
        eco_result.append(raw_data)

    return eco_result


def doubao_android_process_douyin_eco(data,eco_list):
    eco_result = []
    task_id = data.get('taskId')
    platform = data.get('platform')
    req_id = data.get('reqId')
    prompt = data.get('prompt')
    for index, item in enumerate(eco_list):
        raw_data = {
            "eco_id": item.get('pid', ''),
            "eco_url": item.get('jump_url', '') ,
            "eco_title": item.get('text', ''),
            "eco_index": index+1,
            "eco_pic": item.get('image_url', ''),
            "eco_price": item.get('priceShowText', ''),
            "eco_source": 'dyeco',
            "platform": platform,
            "task_id": task_id,
            "req_id": req_id,
            "prompt": prompt
        }
        eco_result.append(raw_data)

    return eco_result



def yuanbao_android_process_jd_eco(data,eco_list):
    eco_result = []
    task_id = data.get('taskId')
    platform = data.get('platform')
    req_id = data.get('reqId')
    prompt = data.get('prompt')
    for index, item in enumerate(eco_list):
        raw_data = {
            "eco_id": item.get('sku', ''),
            "eco_url": item.get('pc_url', '') ,
            "eco_title": item.get('sku_name', ''),
            "eco_index": index+1,
            "eco_pic": item.get('image_url', ''),
            "eco_price": item.get('price', ''),
            "eco_source": 'jdeco',
            "platform": platform,
            "task_id": task_id,
            "req_id": req_id,
            "prompt": prompt
        }
        eco_result.append(raw_data)

    return eco_result


def save_eco_data_to_bh(data,eco_type,eco_list):

    platform = data.get('platform')

    eco_result = []
    if platform == 'TYQWA':
        if eco_type == 'taobao':
            eco_result = qianwen_android_process_taobao_eco(data,eco_list)
        if eco_type == 'damai':
            eco_result = qianwen_android_process_damai_eco(data, eco_list)
    if platform == 'DOUBA':
        if eco_type == 'dypoi':
            ...
        if eco_type == 'dyeco':
            eco_result =doubao_android_process_douyin_eco(data,eco_list)
    if platform == 'TXYBA':
        if eco_type == 'jdeco':
            eco_result =yuanbao_android_process_jd_eco(data,eco_list)

    bh_utils.insert_data('geo_eco_data',eco_result)


