package com.gingersoft.gsa.cloud.table.mvp.model.bean;

import com.gingersoft.gsa.cloud.base.common.bean.OrderBean;
import com.gingersoft.gsa.cloud.base.common.bean.OrderDetail;

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

import static com.gingersoft.gsa.cloud.base.common.bean.OrderDetail.FOOD_TYPE;
import static com.gingersoft.gsa.cloud.base.common.bean.OrderDetail.getItemType;

/**
 * 作者：ELEGANT_BIN
 * 版本：1.6.0
 * 创建日期：2020-03-14
 * 修订历史：2020-03-14
 * 描述：已結賬訂單
 */
public class OrderDetailItem implements Serializable {

    /**
     * success : true
     * sysTime : 1584168902700
     * data : [{"id":47040,"orderNo":"gs200371144969589","status":0,"totalAmount":10,"totalPoints":0,"createTime":"Mar 14, 2020 1:24:12 PM","person":2,"orderDetails":[{"id":1639952,"orderId":47040,"parentId":0,"productName":"包子","productId":"14520","price":5,"lunchboxPrice":0,"number":1,"type":3,"createTime":"Mar 14, 2020 2:55:02 PM","status":0},{"id":1639953,"orderId":47040,"parentId":0,"productName":"燒麥","productId":"14522","price":5,"lunchboxPrice":0,"number":1,"type":3,"createTime":"Mar 14, 2020 2:55:02 PM","status":0}]},{"id":47039,"orderNo":"gs200741188764794","status":4,"totalAmount":1015,"totalPoints":0,"createTime":"Mar 14, 2020 1:18:32 PM","person":5,"orderDetails":[{"id":1639951,"orderId":47039,"parentId":0,"productName":"餃子","productId":"14521","price":10,"lunchboxPrice":0,"number":1,"type":3,"createTime":"Mar 14, 2020 2:55:02 PM","status":0},{"id":1639956,"orderId":47039,"parentId":0,"productName":"火鍋","productId":"14527","price":200,"lunchboxPrice":0,"number":5,"type":3,"createTime":"Mar 14, 2020 2:55:02 PM","status":0},{"id":1639957,"orderId":47039,"parentId":1639956,"productName":"加醋","productId":"8563","price":1,"lunchboxPrice":0,"number":5,"type":4,"createTime":"Mar 14, 2020 2:55:02 PM","status":0},{"id":1639958,"orderId":47039,"parentId":1639956,"productName":"青菜","productId":"965","price":0,"lunchboxPrice":0,"number":5,"type":3,"createTime":"Mar 14, 2020 2:55:02 PM","status":0}]},{"id":47038,"orderNo":"gs200451176160673","status":4,"totalAmount":3325,"totalPoints":0,"createTime":"Mar 14, 2020 1:08:44 PM","person":5,"orderDetails":[{"id":1639946,"orderId":47038,"parentId":0,"productName":"壽司","productId":"14534","price":20,"lunchboxPrice":0,"number":50,"type":3,"createTime":"Mar 14, 2020 2:55:02 PM","status":0},{"id":1639947,"orderId":47038,"parentId":1639946,"productName":"加牛肉","productId":"8566","price":20,"lunchboxPrice":0,"number":50,"type":4,"createTime":"Mar 14, 2020 2:55:02 PM","status":0},{"id":1639948,"orderId":47038,"parentId":1639946,"productName":"木頭飯","productId":"963","price":25,"lunchboxPrice":0,"number":50,"type":3,"createTime":"Mar 14, 2020 2:55:02 PM","status":0},{"id":1639949,"orderId":47038,"parentId":0,"productName":"餃子","productId":"14521","price":10,"lunchboxPrice":0,"number":5,"type":3,"createTime":"Mar 14, 2020 2:55:02 PM","status":0},{"id":1639950,"orderId":47038,"parentId":0,"productName":"燒麥","productId":"14522","price":5,"lunchboxPrice":0,"number":5,"type":3,"createTime":"Mar 14, 2020 2:55:02 PM","status":0}]},{"id":47037,"orderNo":"gs200001100863294","status":4,"totalAmount":162555,"totalPoints":0,"createTime":"Mar 14, 2020 1:00:45 PM","person":2,"orderDetails":[{"id":1639940,"orderId":47037,"parentId":0,"productName":"雞米花","productId":"14536","price":20,"lunchboxPrice":0,"number":1,"type":3,"createTime":"Mar 14, 2020 2:55:02 PM","status":0},{"id":1639941,"orderId":47037,"parentId":0,"productName":"奶茶-顯示","productId":"14532","price":15,"lunchboxPrice":0,"number":1,"type":3,"createTime":"Mar 14, 2020 2:55:02 PM","status":0},{"id":1639942,"orderId":47037,"parentId":0,"productName":"壽司","productId":"14534","price":1000,"lunchboxPrice":0,"number":50,"type":3,"createTime":"Mar 14, 2020 2:55:02 PM","status":0},{"id":1639943,"orderId":47037,"parentId":1639942,"productName":"加牛肉","productId":"8566","price":1000,"lunchboxPrice":0,"number":50,"type":4,"createTime":"Mar 14, 2020 2:55:02 PM","status":0},{"id":1639944,"orderId":47037,"parentId":1639942,"productName":"木頭飯","productId":"963","price":1250,"lunchboxPrice":0,"number":50,"type":3,"createTime":"Mar 14, 2020 2:55:02 PM","status":0},{"id":1639945,"orderId":47037,"parentId":0,"productName":"西紅柿蛋湯","productId":"14526","price":20,"lunchboxPrice":0,"number":1,"type":3,"createTime":"Mar 14, 2020 2:55:02 PM","status":0}]},{"id":47036,"orderNo":"gs201841108269516","status":4,"totalAmount":15,"totalPoints":0,"createTime":"Mar 14, 2020 12:59:26 PM","person":2,"orderDetails":[{"id":1639938,"orderId":47036,"parentId":0,"productName":"餃子","productId":"14521","price":10,"lunchboxPrice":0,"number":1,"type":3,"createTime":"Mar 14, 2020 2:55:02 PM","status":0},{"id":1639939,"orderId":47036,"parentId":0,"productName":"燒麥","productId":"14522","price":5,"lunchboxPrice":0,"number":1,"type":3,"createTime":"Mar 14, 2020 2:55:02 PM","status":0}]},{"id":47035,"orderNo":"gs200511160960157","status":4,"totalAmount":502500,"totalPoints":0,"createTime":"Mar 14, 2020 12:43:10 PM","person":2,"orderDetails":[{"id":1639935,"orderId":47035,"parentId":0,"productName":"火鍋","productId":"14527","price":10000,"lunchboxPrice":0,"number":50,"type":3,"createTime":"Mar 14, 2020 2:55:02 PM","status":0},{"id":1639936,"orderId":47035,"parentId":1639935,"productName":"加醋","productId":"8563","price":50,"lunchboxPrice":0,"number":50,"type":4,"createTime":"Mar 14, 2020 2:55:02 PM","status":0},{"id":1639937,"orderId":47035,"parentId":1639935,"productName":"青菜","productId":"965","price":0,"lunchboxPrice":0,"number":50,"type":3,"createTime":"Mar 14, 2020 2:55:02 PM","status":0}]},{"id":47034,"orderNo":"gs201081124266644","status":4,"totalAmount":20,"totalPoints":0,"createTime":"Mar 14, 2020 12:41:22 PM","person":2,"orderDetails":[{"id":1639932,"orderId":47034,"parentId":0,"productName":"包子","productId":"14520","price":5,"lunchboxPrice":0,"number":1,"type":3,"createTime":"Mar 14, 2020 2:55:02 PM","status":0},{"id":1639933,"orderId":47034,"parentId":0,"productName":"燒麥","productId":"14522","price":5,"lunchboxPrice":0,"number":1,"type":3,"createTime":"Mar 14, 2020 2:55:02 PM","status":0},{"id":1639934,"orderId":47034,"parentId":0,"productName":"餃子","productId":"14521","price":10,"lunchboxPrice":0,"number":1,"type":3,"createTime":"Mar 14, 2020 2:55:02 PM","status":0}]},{"id":47033,"orderNo":"gs200771176264819","status":4,"totalAmount":1005,"totalPoints":0,"createTime":"Mar 14, 2020 12:27:24 PM","person":5,"orderDetails":[{"id":1639929,"orderId":47033,"parentId":0,"productName":"火鍋","productId":"14527","price":200,"lunchboxPrice":0,"number":5,"type":3,"createTime":"Mar 14, 2020 2:55:02 PM","status":0},{"id":1639930,"orderId":47033,"parentId":1639929,"productName":"加醋","productId":"8563","price":1,"lunchboxPrice":0,"number":5,"type":4,"createTime":"Mar 14, 2020 2:55:02 PM","status":0},{"id":1639931,"orderId":47033,"parentId":1639929,"productName":"青菜","productId":"965","price":0,"lunchboxPrice":0,"number":5,"type":3,"createTime":"Mar 14, 2020 2:55:02 PM","status":0}]},{"id":47029,"orderNo":"gs200551108069942","status":4,"totalAmount":1055,"totalPoints":0,"createTime":"Mar 14, 2020 12:17:27 PM","person":5,"orderDetails":[{"id":1639912,"orderId":47029,"parentId":0,"productName":"餃子","productId":"14521","price":10,"lunchboxPrice":0,"number":5,"type":3,"createTime":"Mar 14, 2020 2:55:02 PM","status":0},{"id":1639913,"orderId":47029,"parentId":0,"productName":"火鍋","productId":"14527","price":200,"lunchboxPrice":0,"number":5,"type":3,"createTime":"Mar 14, 2020 2:55:02 PM","status":0},{"id":1639914,"orderId":47029,"parentId":1639913,"productName":"加醋","productId":"8563","price":1,"lunchboxPrice":0,"number":5,"type":4,"createTime":"Mar 14, 2020 2:55:02 PM","status":0},{"id":1639915,"orderId":47029,"parentId":1639913,"productName":"青菜","productId":"965","price":0,"lunchboxPrice":0,"number":5,"type":3,"createTime":"Mar 14, 2020 2:55:02 PM","status":0}]},{"id":47028,"orderNo":"gs200441188067145","status":4,"totalAmount":330,"totalPoints":0,"createTime":"Mar 14, 2020 12:11:34 PM","person":5,"orderDetails":[{"id":1639908,"orderId":47028,"parentId":0,"productName":"拉麵","productId":"14529","price":50,"lunchboxPrice":0,"number":5,"type":3,"createTime":"Mar 14, 2020 2:55:02 PM","status":0},{"id":1639909,"orderId":47028,"parentId":1639908,"productName":"牛奶","productId":"964","price":5,"lunchboxPrice":0,"number":5,"type":3,"createTime":"Mar 14, 2020 2:55:02 PM","status":0},{"id":1639910,"orderId":47028,"parentId":0,"productName":"拉麵","productId":"14529","price":50,"lunchboxPrice":0,"number":1,"type":3,"createTime":"Mar 14, 2020 2:55:02 PM","status":0},{"id":1639911,"orderId":47028,"parentId":1639910,"productName":"牛奶","productId":"964","price":5,"lunchboxPrice":0,"number":1,"type":3,"createTime":"Mar 14, 2020 2:55:02 PM","status":0}]}]
     */

    /**
     * id : 47040
     * tableName : 4
     * tableId : 1694
     * orderNo : gs200371144969589
     * status : 0
     * totalAmount : 10
     * totalPoints : 0
     * amount : 15
     * createTime : Mar 14, 2020 1:24:12 PM
     * endTime : Mar 14, 2020 1:24:12 PM
     * person : 2
     * payName : 支付寶
     * orderPayType : 0
     * tipsPrice : 5
     * linePayType : 1
     * orderDetails : [{"id":1639952,"orderId":47040,"parentId":0,"productName":"包子","productId":"14520","price":5,"lunchboxPrice":0,"number":1,"type":3,"createTime":"Mar 14, 2020 2:55:02 PM","status":0},{"id":1639953,"orderId":47040,"parentId":0,"productName":"燒麥","productId":"14522","price":5,"lunchboxPrice":0,"number":1,"type":3,"createTime":"Mar 14, 2020 2:55:02 PM","status":0}]
     */
    private long id;
    private int status;
    private String orderNo;
    private String tableName;
    private int tableId;
    /**總金額*/
    private double totalAmount;
    private int totalPoints;
    /**支付金額*/
    private double amount;
    private String payName;
    private String orderPayType;
    private double tipsPrice;
    private byte linePayType;
    /**生成訂單時間*/
    private String createTime;
    /**結賬時間*/
    private String endTime;
    private int person;
    private List<OrderBean.OrderDetailsBean> orderDetails;

    /**
     * 訂單狀態:0:未支付;1:待確認(已支付, 待餐廳確認);2:制作中（餐厅确认）;3:派送中;4:确认收货（完成）;5:是否评论;6:取消;
     */
    public static final byte STATUS_UNPAID = 0;
    public static final byte STATUS_NOT_CONFIRM = 1;
    public static final byte STATUS_Making = 2;
    public static final byte STATUS_Dispatching = 3;
    public static final byte STATUS_CONFIRM = 4;
    public static final byte STATUS_COMMENT = 5;
    public static final byte STATUS_CANCEL = 6;

    public long getId() {
        return id;
    }

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

    public String getTableName() {
        return tableName;
    }

    public void setTableName(String tableName) {
        this.tableName = tableName;
    }

    public int getTableId() {
        return tableId;
    }

    public void setTableId(int tableId) {
        this.tableId = tableId;
    }

    public String getOrderNo() {
        return orderNo;
    }

    public void setOrderNo(String orderNo) {
        this.orderNo = orderNo;
    }

    public String getOrderPayType() {
        return orderPayType;
    }

    public void setOrderPayType(String orderPayType) {
        this.orderPayType = orderPayType;
    }

    public double getTipsPrice() {
        return tipsPrice;
    }

    public void setTipsPrice(double tipsPrice) {
        this.tipsPrice = tipsPrice;
    }

    public byte getLinePayType() {
        return linePayType;
    }

    public void setLinePayType(byte linePayType) {
        this.linePayType = linePayType;
    }

    public String getPayName() {
        return payName;
    }

    public void setPayName(String payName) {
        this.payName = payName;
    }

    public int getStatus() {
        return status;
    }

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

    public double getTotalAmount() {
        return totalAmount;
    }

    public void setTotalAmount(double totalAmount) {
        this.totalAmount = totalAmount;
    }

    public int getTotalPoints() {
        return totalPoints;
    }

    public void setTotalPoints(int totalPoints) {
        this.totalPoints = totalPoints;
    }

    public double getAmount() {
        return amount;
    }

    public void setAmount(double amount) {
        this.amount = amount;
    }

    public String getCreateTime() {
        return createTime;
    }

    public void setCreateTime(String createTime) {
        this.createTime = createTime;
    }

    public String getEndTime() {
        return endTime;
    }

    public void setEndTime(String endTime) {
        this.endTime = endTime;
    }

    public int getPerson() {
        return person;
    }

    public void setPerson(int person) {
        this.person = person;
    }

    public List<OrderBean.OrderDetailsBean> getOrderDetails() {
        return orderDetails;
    }

    public void setOrderDetails(List<OrderBean.OrderDetailsBean> orderDetails) {
        this.orderDetails = orderDetails;
    }

    public static List<OrderDetail> orderTransOrderDetails(List<OrderBean.OrderDetailsBean> orderDetails) {
        List<OrderDetail> orderDetailList = new ArrayList<>();
        OrderDetail parentOrderDetail = null;
        for (OrderBean.OrderDetailsBean orderDetailsBean : orderDetails) {
            OrderDetail orderDetail = new OrderDetail();
            orderDetail.setId(orderDetailsBean.getId());
            orderDetail.setProductId(orderDetailsBean.getProductId());
            orderDetail.setOrderId(orderDetailsBean.getOrderId());
            orderDetail.setParentId(orderDetailsBean.getParentId());
            orderDetail.setProductName(orderDetailsBean.getProductName());
            orderDetail.setNumber(orderDetailsBean.getNumber());
            orderDetail.setPrice(orderDetailsBean.getPrice());
            orderDetail.setVisible(orderDetailsBean.getStatus() == 0);
//            orderDetail.setAutomod(foods.getAutomod());
            orderDetail.setIsfood(orderDetailsBean.getType() == FOOD_TYPE);
            orderDetail.setNew(false);
            orderDetail.setType(orderDetailsBean.getType());
            orderDetail.setItemType(getItemType(orderDetailsBean, parentOrderDetail));
            orderDetailList.add(orderDetail);
            if (orderDetail.isIsfood()) {
                parentOrderDetail = orderDetail;
            }
        }
        return orderDetailList;
    }

}
