package com.wasu.cs.model;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

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

import com.wasu.module.datafetch.DataFetchException;
import com.wasu.module.datafetch.ObjectBase;
import com.wasu.module.log.WLog;

public class FocusNewSeries extends ObjectBase {
	
	private static final long serialVersionUID = 1L;

	private static final String TAG = FocusNewSeries.class.getSimpleName();
	private List<FocusNewItem> movies = null;

	public List<FocusNewItem> getFocusNew() {
		return movies;
	}

	@Override
	public void createFromResponse(String response) throws DataFetchException {
		WLog.i(TAG, response);
		try {
			JSONObject root = new JSONObject(response);
			int code = root.optInt("code");
			if (code != 200) {
				return;
			}
			movies = new ArrayList<FocusNewItem>();
			//JSONObject data = root.optJSONObject("data");
			JSONArray list = root.optJSONArray("data");
			
			int length = list.length();
			for (int i = 0; i < length; i++) {
				JSONObject item = list.optJSONObject(i);
				
				FocusNewItem obj = new FocusNewItem();
				obj.setCurrentServal(item.optInt("episode"));
				obj.setId(item.optInt("id"));
				obj.setJsonUrl(item.optString("jsonUrl"));
				obj.setLayoutCode(item.optString("layout"));
				obj.setName(item.optString("title"));
				obj.setPicUrl(item.optString("picUrl"));
				obj.setTotalServal(item.optInt("itemNum"));
				
				movies.add(obj);
			}
		} catch (JSONException e) {
			e.printStackTrace();
		}
	}
	
	public class FocusNewItem implements Serializable {
		
		private static final long serialVersionUID = 1L;
		
		private int currentServal;
		private int id;
		private String jsonUrl;
		private String layoutCode;
		private String name;
		private String picUrl;
		private int totalServal;

		public int getId() {
			return id;
		}
		
		public void setId(int id) {
			this.id = id;
		}
		
		public String getJsonUrl() {
			return jsonUrl;
		}
		
		public void setJsonUrl(String url) {
			jsonUrl = url;
		}
		
		public String getLayoutCode() {
			return layoutCode;
		}

		public void setLayoutCode(String layoutCode) {
			this.layoutCode = layoutCode;
		}
		
		public String getPicUrl() {
			return picUrl;
		}

		public void setPicUrl(String url) {
			picUrl = url;
		}
		
		public int getCurrentServal() {
			return currentServal;
		}
		
		public void setCurrentServal(int currentServal) {
			this.currentServal = currentServal;
		}
		
		public String getName() {
			return name;
		}

		public void setName(String name) {
			this.name = name;
		}

		public int getTotalServal() {
			return totalServal;
		}

		public void setTotalServal(int totalServal) {
			this.totalServal = totalServal;
		}
	}

}
