anchor.diff:  -export([code_change/3]).
   
   -type user_id() :: integer().
  --record(bid, {bidder :: user_id(), amount :: eb_money:money(), time :: calendar:datetime(), automatic :: boolean()}).
  +-record(bid, {bidder :: user_id(), amount :: eb_money:money(), time :: calendar:datetime(), automatic = false :: boolean()}).
   -record(state, {starting_price :: eb_money:money(), bids = [] :: [#bid{}], high_bid :: #bid{}}).
   
   %% API.
  
positive.code:     end.
  
  bid_lower_than_or_equal_to_high_bid(State, MaxBid, UserId, BidTime, HighBid) ->
      Bid = #bid{bidder = UserId, amount = MaxBid, time = BidTime, automatic = false},
      NewAmount = eb_money:add(MaxBid, eb_bid_increments:get(MaxBid)),
      NewHighBid = case NewAmount < HighBid#bid.amount of
          true ->
              #bid{bidder = HighBid#bid.bidder, amount = NewAmount, time = HighBid#bid.time, automatic = true};
          false ->
              #bid{bidder = HighBid#bid.bidder, amount = HighBid#bid.amount, time = HighBid#bid.time, automatic = false}
      end,
      NewState = State#state{bids = [NewHighBid | [Bid | State#state.bids]]},
      {reply, bid_accepted, NewState}.
  
  bid_higher_than_current_high_bid(State, MaxBid, UserId, BidTime, HighBid) ->
      Bid = #bid{bidder = HighBid#bid.bidder, amount = HighBid#bid.amount, time = HighBid#bid.time, automatic = false},
      NewAmount = eb_money:add(HighBid#bid.amount, eb_bid_increments:get(HighBid#bid.amount)),
      NewHighBid = case NewAmount < MaxBid of
          true ->
              #bid{bidder = UserId, amount = NewAmount, time = BidTime, automatic = true};
          false ->
              #bid{bidder = UserId, amount = MaxBid, time = BidTime, automatic = false}
      end,
      NewState = State#state{bids = [NewHighBid | [Bid | State#state.bids]]},
      {reply, bid_accepted, NewState}.
  
negative.code: 
  handle_call({bid, UserId, MaxBid}, _From, State) when State#state.bids =:= [] ->
      BidTime = calendar:universal_time(),
      Bid = #bid{bidder = UserId, amount = State#state.starting_price, time = BidTime},
      NewState = State#state{bids = [Bid | State#state.bids], high_bid = #bid{bidder = UserId, amount = MaxBid, time = BidTime}},
      {reply, bid_accepted, NewState};
  
  