package com.sheep.gamegroup.model.entity;

import android.text.TextUtils;
import android.widget.TextView;

import com.kfzs.duanduan.utils.NumberFormatUtils;

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

/**
 * Created by ljy on 2018/9/4.
 */

public class GameEntity implements Serializable{
    private int accepted_task_id;//integer($int64)领取福利时使用

    private PlayGameEntity app;
    private boolean can_download;//boolean
    private int is_reservation;//integer($int64)0 不是 1是预约

    private boolean received_voucher;//boolean是否已经领取了福利

    private int release_task_id;//integer($int64)发布任务id

    private int status;//integer($int64)福利任务时使用，和任务记录一样

    private TaskReleaseEty release_task;

    private List<GiftBagApp> has_gift_bag;

    public TaskReleaseEty getRelease_task() {
        return release_task;
    }

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

    public List<GiftBagApp> getHas_gift_bag() {
        return has_gift_bag;
    }

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

    public int getAccepted_task_id() {
        return accepted_task_id;
    }

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

    public PlayGameEntity getApp() {
        return app;
    }

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

    public boolean getCan_download() {
        return can_download;
    }

    public void setCan_download(boolean can_download) {
        this.can_download = can_download;
    }

    public int getIs_reservation() {
        return is_reservation;
    }

    public void setIs_reservation(int is_reservation) {
        this.is_reservation = is_reservation;
    }

    public boolean getReceived_voucher() {
        return received_voucher;
    }

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

    public int getRelease_task_id() {
        return release_task_id;
    }

    public void setRelease_task_id(int release_task_id) {
        this.release_task_id = release_task_id;
    }

    public int getStatus() {
        return status;
    }

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


    @Override
    public boolean equals(Object obj) {
        return obj instanceof GameEntity && (((release_task != null && release_task.equals(((GameEntity) obj).release_task))
         || (app != null && app.equals(((GameEntity) obj).app))));
    }

    /**
     * 是有有礼包
     * @return
     */
    public boolean isGift(){
        return has_gift_bag != null && has_gift_bag.size() > 0;
    }
    /**
     * 获取奖金的文本表示（这里保留两位有效数字，因为服务器可能返回这样的结果：0.6000000238418579）
     * @return
     */
    public String getBonusText(){
        if(release_task != null){
            return NumberFormatUtils.retainMost2(release_task.getBonus());
        }else {
            return null;
        }
    }

    /**
     * 是否显示整个礼包和福利金额标签
     * trur:不显示
     */
    public boolean isGiftAndBonus(){
        return !isGift() && TextUtils.isEmpty(getBonusText());
    }

    /**
     * 是否游戏任务
     */
    public boolean isGameTask(){
        return release_task != null && release_task.getTask() != null;
    }

    public String downLinks(){
        try {
            if(isGameTask()){
                return release_task.getTask().getDownload_link();
            }else {
                return app.getDownload_url();
            }
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }

    }

}
