#include "auction.hh" #include Auction::Auction(Person& organizer, NFT nft, uint initial_bid) : organizer_{ organizer } , nft_{ std::move(nft) } , highest_bidder_{ nullptr } , highest_bid_{ initial_bid } { if (!nft_ || nft_->empty()) throw std::invalid_argument{ "Invalid nft!" }; } Auction::~Auction() { if (highest_bidder_ == nullptr) organizer_.add_nft(std::move(nft_)); else { highest_bidder_->add_nft(std::move(nft_)); organizer_.add_money(highest_bid_); } } bool Auction::bid(Person& person, uint money) { if (money > highest_bid_) { if (highest_bidder_ == nullptr) highest_bidder_ = &person; else highest_bidder_->add_money(highest_bid_); highest_bid_ = money; highest_bidder_ = &person; highest_bidder_->remove_money(money); return true; } return false; } const std::string& Auction::get_nft_name() const { return *nft_; } uint Auction::get_highest_bid() const { return highest_bid_; }