package com.sheep.gamegroup.model.entity;

import android.support.annotation.IntDef;

import com.sheep.gamegroup.util.ListUtil;

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.util.List;

/**
 * Created by realicing on 2018/10/16.
 * realicing@sina.com
 */
public class CommendApp {

    private Applications app;

    private int order;

    private boolean need;

    private Release_task release_task;

    private int accepted_task_id;

    private int status;

    private boolean received_voucher;

    private List<GiftBagApp> has_gift_bag;

    public void setApp(Applications app) {
        this.app = app;
    }

    public Applications getApp() {
        return this.app;
    }

    public void setOrder(int order) {
        this.order = order;
    }

    public int getOrder() {
        return this.order;
    }

    public void setNeed(boolean need) {
        this.need = need;
    }

    public boolean getNeed() {
        return this.need;
    }

    public void setRelease_task(Release_task release_task) {
        this.release_task = release_task;
    }

    public Release_task getRelease_task() {
        return this.release_task;
    }

    public void setAccepted_task_id(int accepted_task_id) {
        this.accepted_task_id = accepted_task_id;
    }

    public int getAccepted_task_id() {
        return this.accepted_task_id;
    }

    public void setStatus(int status) {
        this.status = status;
    }

    public int getStatus() {
        return this.status;
    }

    public void setReceived_voucher(boolean received_voucher) {
        this.received_voucher = received_voucher;
    }

    public boolean getReceived_voucher() {
        return this.received_voucher;
    }

    public void setHas_gift_bag(List<GiftBagApp> has_gift_bag) {
        this.has_gift_bag = has_gift_bag;
    }

    public List<GiftBagApp> getHas_gift_bag() {
        return this.has_gift_bag;
    }
    //是否是礼包
    public boolean isGift() {
        GiftBagApp item;
        return (item = ListUtil.getItem(has_gift_bag, 0)) != null && item.getGift_bag() != null;//这里认为礼包列表不为空且第一个礼包不为空就是礼包
    }
    //是否是现金任务
    public boolean isXianJinTask() {
        return release_task != null && release_task.getTask() != null && release_task.getTask().isXianJinTask();
    }
    //是否是游戏
    public boolean isGame() {
        return app != null && app.getId() > 0;
    }

    //可以切换到抢任务弹出框
    public boolean needChange() {
        return !need && !hasNextShow();
    }
    public static final int SHOW_NONE = 0;//初始状态
    public static final int SHOW_GAME = 1;//显示游戏
    public static final int SHOW_GIFT = 2;//显示礼包
    public static final int SHOW_TASK = 3;//显示现金任务
    private int curShow = SHOW_NONE;
    //还有展示的形式（游戏，礼包，现金任务）
    public boolean hasNextShow() {
        return curShow < SHOW_TASK && checkNextShow(curShow + 1) != SHOW_NONE;
    }
    //检查是否有下一种展示方式
    private int checkNextShow(int nextShow) {
        switch (nextShow){
            case SHOW_GAME:
                return isGame() ? nextShow : checkNextShow(nextShow + 1);
            case SHOW_GIFT:
                return isGift() ? nextShow : checkNextShow(nextShow + 1);
            case SHOW_TASK:
                return isXianJinTask() ? nextShow : SHOW_NONE;//现金任务后没有可切换的展示形式
        }
        return SHOW_NONE;
    }
    //切换到下一个状态
    public void changNextShow() {
        curShow = checkNextShow(curShow + 1);
    }

    @IntDef({SHOW_GAME, SHOW_GIFT, SHOW_TASK})
    @Retention(RetentionPolicy.SOURCE)
    public @interface SHOW_TYPE {
    }
    public boolean isShow(@SHOW_TYPE int show) {
        return curShow == show;
    }
}
