package com.wasu.cs.mvp.model;

import org.json.JSONArray;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

/**
 * @Description: 新版首页中排数据的二级数据类
 * @Author: Danxingxi
 * @CreateDate: 2016/9/26 10:01
 */
public class BodyListDataModel extends IBaseDataModel {

    private List<AssetsDataModel> bodyList = new ArrayList<>();   //横向list资产,推荐屏 点播屏
    private AssetsDataModel channelsWin = new AssetsDataModel(); //直播窗口信息 ,生活屏
    private List<AssetsDataModel> blocksList = new ArrayList<>(); // 生活屏分排数据下发
    private List<AssetsDataModel> linkImagesList = new ArrayList<>(); // 横向list资产,生活屏

    @Override
    public boolean parseJson(JSONObject json) {

        if(super.parseJson(json)){

            json = json.optJSONObject("data");

            if(json != null){
                JSONArray bodyArray = json.optJSONArray("list");
                JSONArray blocksArray = json.optJSONArray("blocks");
                JSONObject objChannelsWin = json.optJSONObject("channelsWin");
                JSONArray linkImagesArray = json.optJSONArray("linkImages");

                if(bodyArray != null){  ////解析推荐 点播屏body每一排的数据
                    int arrayLength = bodyArray.length();
                    if(arrayLength>0){
                        for(int i=0;i<arrayLength;i++){
                            AssetsDataModel assetsModel = new AssetsDataModel();
                            if(assetsModel.parseJson(bodyArray.optJSONObject(i))){
                                bodyList.add(assetsModel);
                            }
                        }
                    }
                }
                if(blocksArray != null){  //解析生活屏blocks 每一排的数据URL
                    int arrayLength = blocksArray.length();
                    if(arrayLength>0){
                        for(int i=0;i<arrayLength;i++){
                            AssetsDataModel assetsModel = new AssetsDataModel();
                            if (assetsModel.parseJson(blocksArray.optJSONObject(i))) {
                                blocksList.add(assetsModel);
                            }
                        }
                    }
                }

                if(objChannelsWin != null){  //生活片第一排第一个视频轮播资产
                    AssetsDataModel assetsDataModel = new AssetsDataModel();
                    assetsDataModel.parseJson(objChannelsWin);
                    channelsWin = assetsDataModel;
                }else{
                    channelsWin = null;
                }

                if(linkImagesArray != null){  //解析生活屏blocks 每一排的数据URL
                    int arrayLength = linkImagesArray.length();
                    if(arrayLength>0){
                        for(int i=0;i<arrayLength;i++){
                            AssetsDataModel assetsModel = new AssetsDataModel();
                            if (assetsModel.parseJson(linkImagesArray.optJSONObject(i))) {
                                linkImagesList.add(assetsModel);
                            }
                        }
                    }
                }

            }
            return true;
        }
        return false;
    }

    public List<AssetsDataModel> getBodyList() {
        return bodyList;
    }

    public AssetsDataModel getChannelsWin() {
        return channelsWin;
    }

    public List<AssetsDataModel> getBlocksList() {
        return blocksList;
    }

    public List<AssetsDataModel> getLinkImagesList() {
        return linkImagesList;
    }
}
