package tv.acfun.a63.api;

import java.util.List;

import tv.acfun.a63.AcApp;
import tv.acfun.a63.api.entity.Content;

import com.alibaba.fastjson.JSON;

public final class ArticleApi {

    /**
     * @param type
     *            {@code TYPE_*}
     * @param catId
     *            {@code CAT_*}
     * @param count
     *            default 20
     * @param page
     *            default 1
     * @return
     */
    public static String getUrl(int type, int catId, int count, int page) {
        if (count <= 0)
            count = 20;
        if(page <1)
            page = 1;
        return String.format(Constants.URL_BASE, type, catId, count, 20 * (page - 1));
    }

    /**
     * 获得默认形式(最新发布)列表的url
     */
    public static String getDefaultUrl(int channelId, int count, int page) {
        return getUrl(Constants.TYPE_DEFAULT, channelId, count, page);
    }

    /**
     * 获得周热门列表url
     */
    public static String getHotListUrl(int channelId) {
        return getUrl(Constants.TYPE_HOT, channelId, Constants.COUNT_HOT, 1);
    }

    /**
     * 获得最新回复列表url
     */
    public static String getLatestRepliedUrl(int channelId) {
        return getUrl(Constants.TYPE_LATEST_REPLY, channelId, Constants.COUNT_LAST_REPLY, 1);
    }

    public static String getContentUrl(int aid){
        if(aid <=0)
            return null;
        return String.format(Constants.URL_CONTENT, aid);
    }
    
    
    public static List<Content> getChannelContents(String json){
        return JSON.parseArray(json, Content.class);
    }
    
    public static String getCommentUrl(int aid, int page){
        return String.format(Constants.URL_COMMENT, aid,page);
    }
    
    public static boolean isHotArticle(Content art) {
        boolean isHot;
        long e = System.currentTimeMillis() - art.releaseDate;
        if (e <= AcApp._1_hour * 3) {
            isHot = art.comments >= 45 || art.views >= 2500;
        } else if (e <= AcApp._1_hour * 6) {
            isHot = art.comments >= 90 || art.views >= 5000;
        } else if (art.channelId == Constants.CAT_COMIC_LIGHT_NOVEL) {
            isHot = art.comments >= 25 || art.views >= 1200;
        } else if (art.channelId == Constants.CAT_WORK_EMOTION) {
            isHot = art.comments >= 80 || art.views >= 3000;
        } else if (art.channelId == Constants.CAT_AN_CULTURE) {
            isHot = art.comments >= 50 || art.views >= 1400;
        } else {
            isHot = art.comments >= 100 || art.views >= 10000;
        }
        return isHot;
    }
    public static boolean isRecommendedArticle(Content art) {
        boolean isRecommended;
        long e = System.currentTimeMillis() - art.releaseDate;
        if(e<=AcApp._1_hour){
            isRecommended = art.comments >= 10 && art.views >= 300;
        } else if(e<=AcApp._1_hour*3){
            isRecommended = art.comments >= 15 && art.views >= 700 && art.stows >=2;
        }else if(e<=AcApp._1_hour*5){
            isRecommended = art.comments >= 20 && art.views >= 1500 && art.stows>= 5;
        }else if(e<=AcApp._1_hour*12){
            isRecommended = art.comments >= 70 && art.views >= 2800 && art.stows>=25;
        }else
            isRecommended = art.views >= 5000 && art.stows>=50;
            
            return isRecommended;
    }
}

@@ -1885,17 +1885,17 @@
 ents %3E= 
-4
+3
 5 %7C%7C art
@@ -2250,17 +2250,17 @@
 ents %3E= 
-8
+7
 0 %7C%7C art
@@ -2375,17 +2375,17 @@
 ents %3E= 
-5
+4
 0 %7C%7C art
@@ -2770,16 +2770,32 @@
 s %3E= 300
+ && art.stows%3E=1
 ;%0A      
@@ -2793,25 +2793,24 @@
 1;%0A        %7D
- 
 else if(e%3C=A
@@ -2870,17 +2870,17 @@
 ents %3E= 
-1
+2
 5 && art
@@ -2908,17 +2908,17 @@
 stows %3E=
-2
+5
 ;%0A      
@@ -2993,17 +2993,17 @@
 ents %3E= 
-2
+3
 0 && art
@@ -3031,18 +3031,18 @@
 .stows%3E=
- 5
+10
 ;%0A      
@@ -3118,18 +3118,18 @@
 ents %3E= 
-70
+35
  && art.
@@ -3141,10 +3141,10 @@
  %3E= 
-28
+30
 00 &
@@ -3197,24 +3197,46 @@
 ecommended =
+ art.comments %3E= 40 &&
  art.views %3E
@@ -3237,17 +3237,17 @@
 iews %3E= 
-5
+6
 000 && a

no msg