package io.github.zutherb.appstash.shop.service.order.model;

import io.github.zutherb.appstash.shop.service.user.model.UserInfo;
import io.github.zutherb.appstash.shop.service.user.model.UserInfo;

import java.io.Serializable;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.List;

/**
 * @author zutherb
 */
public class OrderInfo implements Serializable {

    private Long orderId;
    private UserInfo user;
    private List<OrderItemInfo> orderItems;
    private DeliveryAddressInfo deliveryAddress;
    private Date orderDate;
    private String sessionId;

    private OrderInfo() {
    }

    public OrderInfo(UserInfo user, DeliveryAddressInfo deliveryAddress, List<OrderItemInfo> orderItems, String sessionId) {
        this.user = user;
        this.orderItems = orderItems;
        this.deliveryAddress = deliveryAddress;
        this.sessionId = sessionId;
    }

    public OrderInfo(Long orderId, String sessionId, OrderInfo orderInfo) {
        this.orderId = orderId;
        this.sessionId = sessionId;
        this.user = orderInfo.getUser();
        this.orderItems = orderInfo.getOrderItems();
        this.deliveryAddress = orderInfo.getDeliveryAddress();
    }

    public OrderInfo(Long orderId, OrderInfo orderInfo, List<OrderItemInfo> orderItemInfos, String sessionId) {
        this(orderId, sessionId, orderInfo);
        this.orderItems = orderItemInfos;
        this.sessionId = sessionId;
    }

    public String getSessionId() {
        return sessionId;
    }

    public UserInfo getUser() {
        return user;
    }

    public void setUser(UserInfo user) {
        this.user = user;
    }

    public List<OrderItemInfo> getOrderItems() {
        if (orderItems == null) {
            orderItems = new ArrayList<>();
        }
        return Collections.unmodifiableList(orderItems);
    }

    public DeliveryAddressInfo getDeliveryAddress() {
        return deliveryAddress;
    }

    public BigDecimal getDiscountSum() {
        BigDecimal totalSum = BigDecimal.ZERO;
        for (OrderItemInfo orderItemInfo : orderItems) {
            totalSum = totalSum.add(orderItemInfo.getTotalSum());
        }
        double fraction = 25/100;
        // return totalSum.multiply(new BigDecimal(Double.toString(fraction)));
        return new BigDecimal("25.50");
    }

    public BigDecimal getTotalSum() {
        BigDecimal totalSum = BigDecimal.ZERO;
        for (OrderItemInfo orderItemInfo : orderItems) {
            totalSum = totalSum.add(orderItemInfo.getTotalSum());
        }
        // double fraction = 25/100;        
        // return totalSum.subtract(totalSum.multiply(new BigDecimal(fraction)));
        
        return totalSum;
    }
    
    
    public Long getOrderId() {
        return orderId;
    }

    public Date getOrderDate() {
        return orderDate;
    }
}

@@ -2225,22 +2225,26 @@
         
-double
+BigDecimal
  fractio
@@ -2247,22 +2247,42 @@
 ction = 
+BigDecimal.valueOf(
 25/100
+)
 ;%0A      
@@ -2274,35 +2274,32 @@
 25/100);%0A       
- //
  return totalSum
@@ -2312,89 +2312,16 @@
 ply(
-new BigDecimal(Double.toString(fraction)));%0A        return new BigDecimal(%2225.50%22
+fraction
 );%0A 

Update OrderInfo.java