<commit_before>package com.bakerbeach.market.cart.model;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Date;
import java.util.LinkedList;
import java.util.List;

import org.bson.types.ObjectId;
import org.mongodb.morphia.annotations.Embedded;
import org.mongodb.morphia.annotations.Entity;
import org.mongodb.morphia.annotations.Id;
import org.mongodb.morphia.annotations.PrePersist;
import org.mongodb.morphia.annotations.Property;
import org.mongodb.morphia.annotations.Transient;
import org.mongodb.morphia.annotations.Version;

import com.bakerbeach.market.core.api.model.Cart;
import com.bakerbeach.market.core.api.model.CartItem;
import com.bakerbeach.market.core.api.model.Coupon;
import com.bakerbeach.market.core.api.model.Total;

@Entity(value="carts", noClassnameStored=true)
public class SimpleCartImpl implements Cart {

	@Id protected ObjectId id;
	@Property("customer_id") protected String customerId;
	@Property("client_id") private String clientId;
	protected String status = "ACTIVE";
	protected String name;
	@Embedded protected List<CartItem> cartItems = new ArrayList<CartItem>();
	@Transient protected List<Coupon> coupons = new ArrayList<Coupon>(1);

	@Transient protected Total total;
	@Transient protected Total discount;
	
	@Transient protected BigDecimal valueOfGoods;
	@Transient protected BigDecimal valueOfShippingGoods;
	@Transient protected BigDecimal shipping;
	@Transient protected BigDecimal payment;
	
	@Property("created_at") protected Date createdAt;
	@Property("created_by") protected String createdBy;
	@Property("updated_at") protected Date updatedAt;
	@Property("updated_by") protected String updatedBy;
		
	@Version
	private Long version;

	@PrePersist
	protected void trackUpdate() {
		Date now = new Date();
		updatedAt = now;
		if (createdAt == null) {
			createdAt = now;
		}
	}

	@Override
	public boolean add(CartItem item) {
		return cartItems.add(item);
	}
	
	@Override
	public boolean addAll(Collection<CartItem> items) {
		return cartItems.addAll(items);
	}

	@Override
	public List<CartItem> getCartItems() {
		return cartItems;
	}

	@Override
	public boolean remove(CartItem item) {
		return cartItems.remove(item);
	}

	@Override
	public void clear() {
		valueOfGoods = null;
		valueOfShippingGoods = null;
		shipping = null;
		payment = null;
		
		total = null;
		coupons = null;
		
		cartItems.clear();
	}

	@Override
	public boolean isEmpty() {
		return cartItems.isEmpty();
	}

	@Override
	public CartItem findItemById(String id) {
		if (id != null) {<commit_msg>cart clear changes<commit_after>package com.bakerbeach.market.cart.model;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Date;
import java.util.LinkedList;
import java.util.List;

import org.bson.types.ObjectId;
import org.mongodb.morphia.annotations.Embedded;
import org.mongodb.morphia.annotations.Entity;
import org.mongodb.morphia.annotations.Id;
import org.mongodb.morphia.annotations.PrePersist;
import org.mongodb.morphia.annotations.Property;
import org.mongodb.morphia.annotations.Transient;
import org.mongodb.morphia.annotations.Version;

import com.bakerbeach.market.core.api.model.Cart;
import com.bakerbeach.market.core.api.model.CartItem;
import com.bakerbeach.market.core.api.model.Coupon;
import com.bakerbeach.market.core.api.model.Total;

@Entity(value="carts", noClassnameStored=true)
public class SimpleCartImpl implements Cart {

	@Id protected ObjectId id;
	@Property("customer_id") protected String customerId;
	@Property("client_id") private String clientId;
	protected String status = "ACTIVE";
	protected String name;
	@Embedded protected List<CartItem> cartItems = new ArrayList<CartItem>();
	@Transient protected List<Coupon> coupons = new ArrayList<Coupon>(1);

	@Transient protected Total total;
	@Transient protected Total discount;
	
	@Transient protected BigDecimal valueOfGoods;
	@Transient protected BigDecimal valueOfShippingGoods;
	@Transient protected BigDecimal shipping;
	@Transient protected BigDecimal payment;
	
	@Property("created_at") protected Date createdAt;
	@Property("created_by") protected String createdBy;
	@Property("updated_at") protected Date updatedAt;
	@Property("updated_by") protected String updatedBy;
		
	@Version
	private Long version;

	@PrePersist
	protected void trackUpdate() {
		Date now = new Date();
		updatedAt = now;
		if (createdAt == null) {
			createdAt = now;
		}
	}

	@Override
	public boolean add(CartItem item) {
		return cartItems.add(item);
	}
	
	@Override
	public boolean addAll(Collection<CartItem> items) {
		return cartItems.addAll(items);
	}

	@Override
	public List<CartItem> getCartItems() {
		return cartItems;
	}

	@Override
	public boolean remove(CartItem item) {
		return cartItems.remove(item);
	}

	@Override
	public void clear() {
		valueOfGoods = null;
		valueOfShippingGoods = null;
		shipping = null;
		payment = null;
		
		total = null;
		coupons = new ArrayList<Coupon>(1);
		
		cartItems.clear();
	}

	@Override
	public boolean isEmpty() {
		return cartItems.isEmpty();
	}

	@Override
	public CartItem findItemById(String id) {
		if (id != null) {
{'fraction_non_alphanumeric': 0.1057857552033607, 'fraction_numerical': 0.0005728470498376934, 'mean_word_length': 5.326086956521739, 'pattern_counts': {'":': 0, '<': 16, '<?xml version=': 0, '>': 16, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4441667', 'n_tokens_mistral': 1752, 'n_tokens_neox': 1653, 'n_words': 393}