package com.sheep.gamegroup.model.entity;


import android.support.annotation.IntDef;
import android.text.TextUtils;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;

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

/**
 * Created by ljy on 2018/5/10.
 */

public class TaskChild implements Serializable {
    private String BeginTime;//1525147200,
    private String Order;//1,
    private String EndTime;//1530115200,
    private String Desc;//"<p>阿斯顿发射的发</p>",
    private String Amount;//1,
    private int Id;//8,
    private int already_accepted_task_id;//8,
    private String task_id;//161,
    private String Time;//0,
    private String Name;//"212312311111111",
    private int TaskType;//
    /*
    1、 任务未开启时——即将开启
2、 任务未领取时——可领取
3、 任务已领取待完成时——进行中
4、 任务已提交待审核——待审核
5、 任务审核通过——已完成
6、 任务审核失败——审核失败
7、任务已过期未完成——已过期
     */
    private int status;//
    private int allowSubmit;//失败或者下线后，是否可以再次提交截图 2 不可以 1 可以

    private int demo_time;//试玩时长(秒)

    private List<TaskDescEntity> descEntityList;

    private TaskDescEntity descEntity;

    /**
     * 截图地址
     */
    private String screenshots;
    private List<ScreenshotsEntity> screenkshotsList;

    //选中状态
    private boolean selectFlag;

    public List<ScreenshotsEntity> getScreenshotsList() {
        return screenkshotsList;
    }

    public void setScreenshotsList(List<ScreenshotsEntity> screenshotsList) {
        this.screenkshotsList = screenshotsList;
    }

    public boolean isSelectFlag() {
        return selectFlag;
    }

    public void setSelectFlag(boolean selectFlag) {
        this.selectFlag = selectFlag;
    }

    public String getScreenshots() {
        return screenshots;
    }

    public void setScreenshots(String screenshots) {
        regroupScreenshots(screenshots);
        this.screenshots = screenshots;
    }

    public int getDemo_time() {
        return demo_time;
    }

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

    public List<TaskDescEntity> getDescEntityList() {
        return descEntityList;
    }

    public void setDescEntityList(List<TaskDescEntity> descEntityList) {
        this.descEntityList = descEntityList;
    }

    public TaskDescEntity getDescEntity() {
        return descEntity;
    }

    public void setDescEntity(TaskDescEntity descEntity) {
        this.descEntity = descEntity;
    }

    public int getStatus() {
        return status;
    }

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

    public String getBeginTime() {
        return BeginTime;
    }

    public void setBeginTime(String beginTime) {
        BeginTime = beginTime;
    }

    public String getOrder() {
        return Order;
    }

    public void setOrder(String order) {
        Order = order;
    }

    public String getEndTime() {
        return EndTime;
    }

    public void setEndTime(String endTime) {
        EndTime = endTime;
    }

    public String getDesc() {
        return Desc;
    }

    public void setDesc(String desc) {
        regroupDesc(desc);
        Desc =desc+"";
    }

    public String getAmount() {
        return Amount;
    }

    public void setAmount(String amount) {
        Amount = amount;
    }

    public int getId() {
        return Id;
    }

    public void setId(int id) {
        Id = id;
    }

    public String getTask_id() {
        return task_id;
    }

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

    public String getTime() {
        return Time;
    }

    public void setTime(String time) {
        Time = time;
    }

    public String getName() {
        return Name;
    }

    public void setName(String name) {
        Name = name;
    }

    public int getTaskType() {
        return TaskType;
    }

    public void setTaskType(int taskType) {
        TaskType = taskType;
    }

    public int getAlready_accepted_task_id() {
        return already_accepted_task_id;
    }

    public void setAlready_accepted_task_id(int already_accepted_task_id) {
        this.already_accepted_task_id = already_accepted_task_id;
    }

    public int getAllowSubmit() {
        return allowSubmit;
    }

    public void setAllowSubmit(int allowSubmit) {
        this.allowSubmit = allowSubmit;
    }

    /**
     * 重组desc字段
     * @param desc
     */
    private Object regroupDesc(String desc){
        if(TextUtils.isEmpty(desc)){
            return desc;
        }
        if(desc.startsWith("[")){
            List<TaskDescEntity> taskDescEntityList = JSONArray.parseArray(desc, TaskDescEntity.class);
            setDescEntityList(taskDescEntityList);
            return taskDescEntityList;
        }else if (desc.startsWith("{")){
            TaskDescEntity taskDescEntity = JSONObject.parseObject(desc, TaskDescEntity.class);
            setDescEntity(taskDescEntity);
            return taskDescEntity;
        }else {
            return desc;
        }
    }
    private Object regroupScreenshots(String desc){
        if(TextUtils.isEmpty(desc)){
            return desc;
        }
        if(desc.startsWith("[")){
            List<ScreenshotsEntity> taskDescEntityList = JSONArray.parseArray(desc, ScreenshotsEntity.class);
            setScreenshotsList(taskDescEntityList);
            return taskDescEntityList;
        }else {
            return desc;
        }
    }






    public boolean isOldTask() {
        return descEntity == null && descEntityList == null;
    }


//    1、 任务未开启时——即将开启
//2、 任务未领取时——可领取
//3、 任务已领取待完成时——进行中
//4、 任务已提交待审核——待审核
//5、 任务审核通过——已完成
//6、 任务审核失败——审核失败
//7、任务已过期未完成——已过期
    //status 子任务状态
    public static final int STATUS_WILL_OPEN = 1;
    public static final int STATUS_CAN_RECEIVE = 2;
    public static final int STATUS_RUNNING = 3;//进行中
    public static final int STATUS_WAIT_INSPECT = 4;
    public static final int STATUS_FINISHED = 5;
    public static final int STATUS_FAIL= 6;//审核失败
    public static final int STATUS_OUT_TIME = 7;


    @IntDef({STATUS_RUNNING, STATUS_FAIL})
    @Retention(RetentionPolicy.SOURCE)
    public @interface STATUS {
    }
}
