package com.sheep.gamegroup.model.entity;

import android.text.TextUtils;

import com.kfzs.duanduan.utils.NumberFormatUtils;
import com.sheep.gamegroup.helper.DownloadHelper;
import com.sheep.gamegroup.util.TimeUtil;

import java.io.Serializable;
import java.util.Locale;

/**
 * 获取已经发布任务
 * Created by ljy on 2018/3/20.
 */

public class Release_task implements Serializable{
    private float bonus;// 0,
    private String create_time;// 0,
    private String deadline;// 0,
    private String duration;// 0,
    private int id;// 0,
    private int cash_task;// 0,
    private String last_num;// 0,
    private String name;//private String string",
    private long online_time;// 0,
    private String online_type;// 0,
    private String release_num;// 0,
    private String remarks;//private String string",
    private int status;// 1手动上线　2自动上线 　3手动下线　4自动下线 5等待上线',
    private String submit_num;// 0,
    private String task_id;// 0,
    private String unaudited_num;// 0,
    private String update_time;// 0

    private int is_hot;// 0,
    private int is_recommend;// 0,
    private int accepted_task_id;// 0,

    private TaskEty task;

    private int cancel_duration;
    private boolean is_running;
    private String child_task_name;//
    private int demo_time;//试玩时长
    private int consume_amount;//最低消费
    private int gift_ratio;//赠送比例，取值0-100
    private int user_task_status;//备注:和任务记录状态一样
    public int getDemo_time() {
        return demo_time;
    }

    public void setDemo_time(int demo_time) {
        this.demo_time = demo_time;
    }

    public String getLabel_color() {
        return label_color;
    }

    public void setLabel_color(String label_color) {
        this.label_color = label_color;
    }

    private String label_color;//

    public String getChild_task_name() {
        return child_task_name;
    }

    public void setChild_task_name(String child_task_name) {
        this.child_task_name = child_task_name;
    }

    public boolean isIs_running() {
        return is_running;
    }

    public void setIs_running(boolean is_running) {
        this.is_running = is_running;
    }

    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 int getIs_hot() {
        return is_hot;
    }

    public void setIs_hot(int is_hot) {
        this.is_hot = is_hot;
    }

    public int getIs_recommend() {
        return is_recommend;
    }

    public void setIs_recommend(int is_recommend) {
        this.is_recommend = is_recommend;
    }

    public int getCancel_duration() {
        return cancel_duration;
    }

    public void setCancel_duration(int cancel_duration) {
        this.cancel_duration = cancel_duration;
    }

    public void setBonus(float bonus) {
        this.bonus = bonus;
    }

    public float getBonus() {
        return bonus;
    }

    public String getCreate_time() {
        return create_time;
    }

    public void setCreate_time(String create_time) {
        this.create_time = create_time;
    }

    public String getDeadline() {
        return (TextUtils.isEmpty(deadline) || deadline.equals("0")) ? "永久" : deadline;
    }

    public void setDeadline(String deadline) {
        this.deadline = deadline;
    }

    public String getDuration() {
        return duration;
    }

    public void setDuration(String duration) {
        this.duration = duration;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getLast_num() {
        return TextUtils.isEmpty(last_num)?"0":last_num;
    }

    public void setLast_num(String last_num) {
        this.last_num = last_num;
    }

    public String getName() {
        return name;
    }

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

    public long getOnline_time() {
        return online_time;
    }

    public void setOnline_time(long online_time) {
        this.online_time = online_time;
    }

    public String getOnline_type() {
        return online_type;
    }

    public void setOnline_type(String online_type) {
        this.online_type = online_type;
    }

    public String getRelease_num() {
        return TextUtils.isEmpty(release_num)?"0":release_num;
    }

    public void setRelease_num(String release_num) {
        this.release_num = release_num;
    }

    public String getRemarks() {
        return remarks;
    }

    public void setRemarks(String remarks) {
        this.remarks = remarks;
    }

    public int getStatus() {
        return status;
    }

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

    public String getSubmit_num() {
        return submit_num;
    }

    public void setSubmit_num(String submit_num) {
        this.submit_num = submit_num;
    }

    public String getTask_id() {
        return TextUtils.isEmpty(task_id)?"0":task_id;
    }

    public void setTask_id(String task_id) {
        this.task_id = task_id;
    }

    public String getUnaudited_num() {
        return unaudited_num;
    }

    public void setUnaudited_num(String unaudited_num) {
        this.unaudited_num = unaudited_num;
    }

    public String getUpdate_time() {
        return update_time;
    }

    public void setUpdate_time(String update_time) {
        this.update_time = update_time;
    }


    public TaskEty getTask() {
        return task;
    }

    public void setTask(TaskEty task) {
        this.task = task;
    }

    public int getCash_task() {
        return cash_task;
    }

    public void setCash_task(int cash_task) {
        this.cash_task = cash_task;
    }

    public int getGift_ratio() {
        return gift_ratio;
    }

    public void setGift_ratio(int gift_ratio) {
        this.gift_ratio = gift_ratio;
    }

    public int getUser_task_status() {
        return user_task_status;
    }

    public void setUser_task_status(int user_task_status) {
        this.user_task_status = user_task_status;
    }

    public int getConsume_amount() {
        return consume_amount;
    }

    public void setConsume_amount(int consume_amount) {
        this.consume_amount = consume_amount;
    }

    @Override
    public boolean equals(Object obj) {
        return obj instanceof Release_task && ((Release_task) obj).getId() == id;
    }


    /**
     * 获取奖金的文本表示（这里保留两位有效数字，因为服务器可能返回这样的结果：0.6000000238418579）
     * @return
     */
    public String getBonusText() {
        return NumberFormatUtils.retainMost2(bonus);
    }


    public String getCashOrWelfare(){
        switch (cash_task){
            case 2:
                return "福利";
            case 1:
            default:
                return "现金";
        }
    }
    /**
     * 任务是否下线
     * @return
     */
    public boolean isOffline() {
        return status == 3 || status == 4;
    }


    private DownloadHelper downloadHelper = new DownloadHelper();

    public DownloadHelper getDownloadHelper() {
        return downloadHelper;
    }

    /**
     * 福利内容
     * @return
     */
    public String getGiftRatioText() {
        return String.format(Locale.CHINA, "最低充%d，每充%d送%d", consume_amount, consume_amount, gift_ratio * consume_amount / 100);
    }
    /**
     * 剩余份数
     * @return
     */
    public String getLastNumText() {
        return String.format(Locale.CHINA, "剩余%s份", last_num);
    }
    public int getLastNum1Or0(){
        int lastNum = NumberFormatUtils.parseInteger(last_num, 0);
        return lastNum > 0 ? 1 : 0;
    }
    public String getDateText() {
        long endTime = NumberFormatUtils.parseLong(deadline);
        if(endTime < 1000_000){
            return "永久";
        }
        return String.format(Locale.CHINA, "%s—%s", TimeUtil.TimeStamp2Date(online_time, "yyyy/MM/dd"), TimeUtil.TimeStamp2Date(endTime, "yyyy/MM/dd"));
    }

    /**
     * 任务是否已经完成，对于游戏任务或者福利来说，就是已经领取奖励
     * @return
     */
    public boolean isTaskFinished() {
        return user_task_status == 3;
    }

    public String getH5BonusText() {
        return String.format(Locale.CHINA, "<font color='#ff2d4b' size='1'>￥</font><font color='#ff2d4b'>%s</font>", getBonusText());
    }
}
