import logging
from domain.lsp.shanxipukka_domain import ShanXiPukka
from domain.lsp.value_object import CodeFactory

logger = logging.getLogger(__file__)


class XinJiangMobile(ShanXiPukka):
    # 后期需增加审批号字段，approval_num
    MediaExt_Required_Args = ("media_horpic", "focus")

    def __init__(self, alias="XINJIANGIPTV"):
        super().__init__(alias)
        self.lsp_id = self.conf.lsp_id
        self.csp_id = self.conf.csp_id
        self.cms_api = self.conf.cms_api
        self.csp_name = self.conf.csp_name
        self.code_factory = CodeFactory(self.csp_id)
        self.genre_sep = "|"

    def property_program(self, _id, name, media, action="REGIST"):
        search_name = self.transform_chinese_to_letter(name.replace(" ", ""))
        return {
            "element_type": "Program",
            "id": _id,
            "code": _id,
            "action": action,
            "property": [
                {"Name": name},
                {"SearchName": search_name},
                {"OrgAirDate": media.date_published},
                {"Keywords": search_name},
                {"Tags": self.get_genre(media)},
                {"VolumnCount": media.episodes},
                {"Description": media.storyline},
                {"Status": 1},
                {"ApprovalNumber": media.mediaextfieldmodel.approval_num},
                {"LightSpot": media.mediaextfieldmodel.focus},
                {"Duration": int(media.seconds / 60) + 1},
                {"Language": media.languages},
                {"ReleaseYear": media.year},
                {"OriginalCountry": self.get_regions(media)},
                {"ContentProvider": self.csp_name},    # 内容提供商
            ]
        }

    def property_series(self, _id, volumn_count, media, action="REGIST"):
        search_name = self.transform_chinese_to_letter(self.get_media_name_by_alias(media))
        the_property = [
            {"Name": self.get_media_name_by_alias(media)},
            {"OrgAirDate": media.date_published},
            {"Keywords": search_name},
            {"Tags": self.get_genre(media)},
            {"KindDisplay": self.get_genre(media)},
            {"VolumnCount": volumn_count},
            {"Status": 1},
            {"ApprovalNumber": media.mediaextfieldmodel.approval_num},
            {"LightSpot": media.mediaextfieldmodel.focus},
            {"Description": media.storyline},
            {"Duration": int(media.total_seconds / 60) + 1},
            {"Language": media.languages},
            {"ReleaseYear": media.year},
            {"OriginalCountry": self.get_regions(media)},
            {"ContentProvider": self.csp_name},
            {"SearchName": search_name},
        ]
        return {
            "element_type": "Series",
            "id": _id,
            "code": _id,
            "action": action,
            "property": the_property
        }

    def _nope_episode_title(self, media, episode):
        fmt = "第{0}集{1}{2}"
        return fmt.format(episode.serial_num, " ", self.get_media_name_by_alias(media))

