# -*- coding: utf-8 -*-
import json
import os
import sys

from utils.feishu_utils import Feishu

sys.path.append(os.getcwd())


class Material():
    """
    获取品类对应负责人任务明细
    """
    @classmethod
    def get_carry_data(cls, dt, FS_SHEET,NAME):
        data = Feishu.get_values_batch( "Wj0TsRKc0hZrHQtmtg4cZZIwn0c", FS_SHEET )
        processed_list = []
        try:
            for row in data[2:]:
                activate_data = row[4]  # 启动日期
                if not activate_data:
                    continue
                if int(activate_data) != int(dt):
                    continue
                channel_mark = row[0]
                pq_ids = row[2]
                pq_label = row[3] # 站内标签
                video_url = row[5]
                title_category = row[6] #标题类别
                tag_transport_channel = row[7] # 搬运平台
                tag_transport_scene = row[8]  # 搬运场景
                tag_transport_keyword = row[9] # 关键词
                tag = row[10] # 标签
                transform_rule = row[11] # 改造规则
                video_share = row[12] # 片中分享
                trailer_share = row[13]  # 片尾分享
                trailer_share_video = row[14]  # 片尾手动视频
                trailer_share_audio = row[15]  # 片尾分享声音
                trailer_share_bgm = row[16]  # 片尾分享bgm

                video_clipping = row[17]  # 剪裁
                video_clipping_time = row[18]  # 秒数剪裁
                title_transform = row[19]  # 标题改造
                number_dict = {
                    "channel_mark": channel_mark,
                    "name":NAME,
                    "pq_ids": pq_ids,
                    "pq_label": pq_label,
                    "activate_data": activate_data,
                    "video_url": video_url,
                    "title_category": title_category,
                    "tag_transport_channel": tag_transport_channel,
                    "tag_transport_scene": tag_transport_scene,
                    "tag_transport_keyword": tag_transport_keyword,
                    "tag": tag,
                    "transform_rule": transform_rule,
                    "video_share": video_share,
                    "trailer_share": str(trailer_share),
                    "trailer_share_video": trailer_share_video,
                    "trailer_share_audio": trailer_share_audio,
                    "video_clipping": video_clipping,
                    "video_clipping_time": video_clipping_time,
                    "title_transform": title_transform,
                    "trailer_share_bgm": str(trailer_share_bgm),
                    "dt":dt
                }
                processed_list.append(json.dumps(number_dict, ensure_ascii=False))
            return  processed_list
        except:
            return processed_list

    @classmethod
    def get_propmt_data(cls, trailer_share):
        try:
            if "AI片尾引导" not in trailer_share:
                trailer_share = "AI片尾引导"
            data = Feishu.get_values_batch( "Wj0TsRKc0hZrHQtmtg4cZZIwn0c", "Yxg7EK" )
            for row in data[1:]:
                name = row[0]
                if trailer_share == name:
                    return row[1]
            return
        except:
            return None