from spider_man.crawler.extractors import JsonExtractor
from spider_man.crawler.fields import ContainerField, JsonField
from spider_man.spiders.jumei.good.items.good_category_item import GoodCategoryItem

__all__ = ['CategoryGoodPageExtractor']


class CategoryGoodPageExtractor():
    @classmethod
    def get_items(cls, response):
        return cls._extract(response)

    @classmethod
    def _extract(cls, response):
        item_list = []
        for item in CategoryGoodExtractor.get_items(response):
            good_item = GoodCategoryItem()
            good_item['type'] = item.type
            good_item['search_doc_id'] = item.search_doc_id
            good_item['item_id'] = item.item_id
            good_item['status'] = item.status
            good_item['status_num'] = item.status_num
            good_item['selling_forms'] = item.selling_forms
            good_item['settling_accounts_forms'] = item.settling_accounts_forms
            good_item['name'] = item.name
            good_item['qrshare_product_name'] = item.qrshare_product_name
            good_item['short_name'] = item.short_name
            good_item['product_id'] = item.product_id
            good_item['brand_id'] = item.brand_id
            good_item['category_id'] = item.category_id
            good_item['function_ids'] = item.function_ids
            good_item['jumei_price'] = item.jumei_price
            good_item['market_price'] = item.market_price
            good_item['buyer_number'] = item.buyer_number
            good_item['popular'] = item.popular
            good_item['image_url_set'] = item.image_url_set
            good_item['tag'] = item.tag
            good_item['display_price'] = item.display_price
            good_item['wish_number'] = item.wish_number
            good_item['start_time'] = item.start_time
            good_item['end_time'] = item.end_time
            good_item['show_category'] = item.show_category
            good_item['has_short_video'] = item.has_short_video
            good_item['size_attr'] = item.size_attr
            good_item['item_tag'] = item.item_tag
            good_item['sku_last_sale_time'] = item.sku_last_sale_time
            good_item['middle_name'] = item.middle_name
            good_item['selling_point'] = item.selling_point
            good_item['category_v3_1'] = item.category_v3_1
            good_item['tag_id'] = item.tag_id
            good_item['tag_ids'] = item.tag_ids
            good_item['countries'] = item.countries
            good_item['countries_icon'] = item.countries_icon
            good_item['yqt_show'] = item.yqt_show
            good_item['exchange_policy'] = item.exchange_policy
            good_item['price_detail'] = item.price_detail
            good_item['value_of_goods'] = item.value_of_goods
            good_item['tax'] = item.tax
            good_item['live_info'] = item.live_info
            good_item['deal_comments_number'] = item.deal_comments_number
            good_item['total_sales_number'] = item.total_sales_number
            good_item['foreign_language_name'] = item.foreign_language_name
            good_item['abroad_price_foreign'] = item.abroad_price_foreign
            good_item['jumei_price_foreign'] = item.jumei_price_foreign
            good_item['abroad_price'] = item.abroad_price
            good_item['area_currency_symbol'] = item.area_currency_symbol
            good_item['area_currency_symbol_location'] = item.area_currency_symbol_location
            good_item['area_name'] = item.area_name
            good_item['area_icon'] = item.area_icon
            good_item['is_combination'] = item.is_combination
            good_item['product_desc'] = item.product_desc
            good_item['is_dm'] = item.is_dm
            good_item['authorization'] = item.authorization
            good_item['is_deal'] = item.is_deal
            good_item['name_tag'] = item.name_tag
            good_item['time_desc'] = item.time_desc
            good_item['tip_desc'] = item.tip_desc
            good_item['shipping_system_id'] = item.shipping_system_id
            good_item['aca_alliance'] = item.aca_alliance
            good_item['aca_brand'] = item.aca_brand
            good_item['product_reports_number'] = item.product_reports_number
            good_item['stocks_alarm'] = item.stocks_alarm
            good_item['status_tag'] = item.status_tag
            good_item['live'] = item.live
            good_item['video_info'] = item.video_info
            good_item['brand_logo'] = item.brand_logo
            good_item['buried_type'] = item.buried_type
            good_item['exposure_link'] = item.exposure_link
            good_item['click_link'] = item.click_link
            good_item['is_proprietary'] = item.is_proprietary
            good_item['is_sellable_self'] = item.is_sellable_self
            good_item['is_sellable'] = item.is_sellable
            good_item['single_festival_title'] = item.single_festival_title
            good_item['double_festival_title'] = item.double_festival_title
            good_item['festival_price'] = item.festival_price
            good_item['is_activity'] = item.is_activity
            good_item['divideFlag'] = item.divideFlag
            good_item['divideIcon'] = item.divideIcon
            good_item['divideLabel'] = item.divideLabel
            good_item['fake_total_sales_number'] = item.fake_total_sales_number
            good_item['mall_sale_mode'] = item.mall_sale_mode
            good_item['sku_max_price'] = item.sku_max_price
            good_item['sku_min_price'] = item.sku_min_price
            good_item['show_purchase_button'] = item.show_purchase_button
            good_item['policy'] = item.policy
            good_item['url_schema'] = item.url_schema
            good_item['original_image'] = item.original_image
            good_item['category'] = item.category
            good_item['discount_for_market_price'] = item.discount_for_market_price
            good_item['icon_tag'] = item.icon_tag
            item_list.append(good_item)
        return item_list


class CategoryGoodExtractor(JsonExtractor):
    container = ContainerField(json_selector='$.data.item_list[*]')
    type = JsonField(json_selector='$.type')
    search_doc_id = JsonField(json_selector='$.search_doc_id')
    item_id = JsonField(json_selector='$.item_id')
    status = JsonField(json_selector='$.status')
    status_num = JsonField(json_selector='$.status_num')
    selling_forms = JsonField(json_selector='$.selling_forms')
    settling_accounts_forms = JsonField(json_selector='$.settling_accounts_forms')
    name = JsonField(json_selector='$.name')
    qrshare_product_name = JsonField(json_selector='$.qrshare_product_name')
    short_name = JsonField(json_selector='$.short_name')
    product_id = JsonField(json_selector='$.product_id')
    brand_id = JsonField(json_selector='$.brand_id')
    category_id = JsonField(json_selector='$.category_id')
    function_ids = JsonField(json_selector='$.function_ids')
    jumei_price = JsonField(json_selector='$.jumei_price')
    market_price = JsonField(json_selector='$.market_price')
    buyer_number = JsonField(json_selector='$.buyer_number')
    popular = JsonField(json_selector='$.popular')
    image_url_set = JsonField(json_selector='$.image_url_set')
    tag = JsonField(json_selector='$.tag')
    display_price = JsonField(json_selector='$.display_price')
    wish_number = JsonField(json_selector='$.wish_number')
    start_time = JsonField(json_selector='$.start_time')
    end_time = JsonField(json_selector='$.end_time')
    show_category = JsonField(json_selector='$.show_category')
    has_short_video = JsonField(json_selector='$.has_short_video')
    size_attr = JsonField(json_selector='$.size_attr')
    item_tag = JsonField(json_selector='$.item_tag')
    sku_last_sale_time = JsonField(json_selector='$.sku_last_sale_time')
    middle_name = JsonField(json_selector='$.middle_name')
    selling_point = JsonField(json_selector='$.selling_point')
    category_v3_1 = JsonField(json_selector='$.category_v3_1')
    tag_id = JsonField(json_selector='$.tag_id')
    tag_ids = JsonField(json_selector='$.tag_ids')
    countries = JsonField(json_selector='$.countries')
    countries_icon = JsonField(json_selector='$.countries_icon')
    yqt_show = JsonField(json_selector='$.yqt_show')
    exchange_policy = JsonField(json_selector='$.exchange_policy')
    price_detail = JsonField(json_selector='$.price_detail')
    value_of_goods = JsonField(json_selector='$.value_of_goods')
    tax = JsonField(json_selector='$.tax')
    live_info = JsonField(json_selector='$.live_info')
    deal_comments_number = JsonField(json_selector='$.deal_comments_number')
    total_sales_number = JsonField(json_selector='$.total_sales_number')
    foreign_language_name = JsonField(json_selector='$.foreign_language_name')
    abroad_price_foreign = JsonField(json_selector='$.abroad_price_foreign')
    jumei_price_foreign = JsonField(json_selector='$.jumei_price_foreign')
    abroad_price = JsonField(json_selector='$.abroad_price')
    area_currency_symbol = JsonField(json_selector='$.area_currency_symbol')
    area_currency_symbol_location = JsonField(json_selector='$.area_currency_symbol_location')
    area_name = JsonField(json_selector='$.area_name')
    # 地区图标
    area_icon = JsonField(json_selector='$.area_icon')
    is_combination = JsonField(json_selector='$.is_combination')
    # 评论数 （375条评论）
    product_desc = JsonField(json_selector='$.product_desc')
    is_dm = JsonField(json_selector='$.is_dm')
    authorization = JsonField(json_selector='$.authorization')
    is_deal = JsonField(json_selector='$.is_deal')
    name_tag = JsonField(json_selector='$.name_tag')
    time_desc = JsonField(json_selector='$.time_desc')
    tip_desc = JsonField(json_selector='$.tip_desc')
    shipping_system_id = JsonField(json_selector='$.shipping_system_id')
    aca_alliance = JsonField(json_selector='$.aca_alliance')
    aca_brand = JsonField(json_selector='$.aca_brand')
    product_reports_number = JsonField(json_selector='$.product_reports_number')
    stocks_alarm = JsonField(json_selector='$.stocks_alarm')
    status_tag = JsonField(json_selector='$.status_tag')
    live = JsonField(json_selector='$.live')
    video_info = JsonField(json_selector='$.video_info')
    brand_logo = JsonField(json_selector='$.brand_logo')
    buried_type = JsonField(json_selector='$.buried_type')
    exposure_link = JsonField(json_selector='$.exposure_link')
    click_link = JsonField(json_selector='$.click_link')
    is_proprietary = JsonField(json_selector='$.is_proprietary')
    is_sellable_self = JsonField(json_selector='$.is_sellable_self')
    is_sellable = JsonField(json_selector='$.is_sellable')
    single_festival_title = JsonField(json_selector='$.single_festival_title')
    double_festival_title = JsonField(json_selector='$.double_festival_title')
    festival_price = JsonField(json_selector='$.festival_price')
    is_activity = JsonField(json_selector='$.is_activity')
    divideFlag = JsonField(json_selector='$.divideFlag')
    divideIcon = JsonField(json_selector='$.divideIcon')
    divideLabel = JsonField(json_selector='$.divideLabel')
    fake_total_sales_number = JsonField(json_selector='$.fake_total_sales_number')
    mall_sale_mode = JsonField(json_selector='$.mall_sale_mode')
    sku_max_price = JsonField(json_selector='$.sku_max_price')
    sku_min_price = JsonField(json_selector='$.sku_min_price')
    show_purchase_button = JsonField(json_selector='$.show_purchase_button')
    policy = JsonField(json_selector='$.policy')
    url_schema = JsonField(json_selector='$.url_schema')
    original_image = JsonField(json_selector='$.original_image')
    category = JsonField(json_selector='$.category')
    discount_for_market_price = JsonField(json_selector='$.discount_for_market_price')
    icon_tag = JsonField(json_selector='$.icon_tag')