package com.github.catvod.bean; import androidx.annotation.NonNull; import com.google.gson.Gson; import com.google.gson.annotations.SerializedName; import com.google.gson.reflect.TypeToken; import org.json.JSONObject; import java.lang.reflect.Type; import java.util.Arrays; import java.util.Collections; import java.util.HashMap; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; public class Result { @SerializedName("class") private List classes; @SerializedName("list") private List list; @SerializedName("filters") private LinkedHashMap> filters; @SerializedName("header") private String header; @SerializedName("url") private String url; @SerializedName("subs") private List subs; @SerializedName("parse") private int parse; @SerializedName("jx") private int jx; @SerializedName("page") private int page; @SerializedName("pagecount") private int pagecount; @SerializedName("limit") private int limit; @SerializedName("total") private int total; public static String string(List classes, List list, LinkedHashMap> filters) { return Result.get().classes(classes).vod(list).filters(filters).string(); } public static String string(List classes, List list, JSONObject filters) { return Result.get().classes(classes).vod(list).filters(filters).string(); } public static String string(List classes, LinkedHashMap> filters) { return Result.get().classes(classes).filters(filters).string(); } public static String string(List classes, JSONObject filters) { return Result.get().classes(classes).filters(filters).string(); } public static String string(List classes, List list) { return Result.get().classes(classes).vod(list).string(); } public static String string(List list) { return Result.get().vod(list).string(); } public static String string(Vod item) { return Result.get().vod(item).string(); } public static Result get() { return new Result(); } public Result classes(List classes) { this.classes = classes; return this; } public Result vod(List list) { this.list = list; return this; } public Result vod(Vod item) { this.list = Arrays.asList(item); return this; } public Result filters(LinkedHashMap> filters) { this.filters = filters; return this; } public Result filters(JSONObject object) { if (object == null) return this; Type listType = new TypeToken>>() {}.getType(); LinkedHashMap> filters = new Gson().fromJson(object.toString(), listType); for (Map.Entry> entry : filters.entrySet()) for (Filter filter : entry.getValue()) filter.trans(); this.filters = filters; return this; } public Result header(HashMap header) { if (header.isEmpty()) return this; this.header = new Gson().toJson(header); return this; } public Result parse() { this.parse = 1; return this; } public Result parse(int parse) { this.parse = parse; return this; } public Result jx() { this.jx = 1; return this; } public Result url(String url) { this.url = url; return this; } public Result subs(List subs) { this.subs = subs; return this; } public Result page() { return page(1, 1, 0, 1); } public Result page(int page, int count, int limit, int total) { this.page = page > 0 ? page : Integer.MAX_VALUE; this.limit = limit > 0 ? limit : Integer.MAX_VALUE; this.total = total > 0 ? total : Integer.MAX_VALUE; this.pagecount = count > 0 ? count : Integer.MAX_VALUE; return this; } public List getList() { return list == null ? Collections.emptyList() : list; } public String string() { return toString(); } @NonNull @Override public String toString() { return new Gson().toJson(this); } }