package rewards.internal.restaurant; import rewards.Dining; import rewards.internal.account.Account; import common.money.MonetaryAmount; import common.money.Percentage; /** * A restaurant establishment in the network. Like AppleBee's. * * Restaurants calculate how much benefit may be awarded to an account for dining based on a availability policy and a * benefit percentage. */ //TODO 20: Add persistence annotation of restaurant table for mapping with restaurant class public class Restaurant { private Long entityId; private String number; private String name; private Percentage benefitPercentage; private BenefitAvailabilityPolicy benefitAvailabilityPolicy; @SuppressWarnings("unused") private Restaurant() { } /** * Creates a new restaurant. * @param number the restaurant's merchant number * @param name the name of the restaurant */ public Restaurant(String number, String name) { this.number = number; this.name = name; } //TODO 21: Add id annotation //TODO 22: Add id generation strategy. Use GenerationType.AUTO //TODO 23: Add the mapping between the column and the attribute public Long getEntityId() { return entityId; } public void setEntityId(Long entityId) { this.entityId = entityId; } /** * Sets the percentage benefit to be awarded for eligible dining transactions. * @param benefitPercentage the benefit percentage */ public void setBenefitPercentage(Percentage benefitPercentage) { this.benefitPercentage = benefitPercentage; } /** * Sets the policy that determines if a dining by an account at this restaurant is eligible for benefit. * @param benefitAvailabilityPolicy the benefit availability policy */ public void setBenefitAvailabilityPolicy(BenefitAvailabilityPolicy benefitAvailabilityPolicy) { this.benefitAvailabilityPolicy = benefitAvailabilityPolicy; } /** * Returns the name of this restaurant. */ //TODO 24: Add the mapping between the column and the attribute public String getName() { return name; } public void setName(String name) { this.name = name; } /** * Returns the merchant number of this restaurant. */ //TODO 25: Add the mapping between the column and the attribute public String getNumber() { return number; } public void setNumber(String number) { this.number = number; } /** * Returns this restaurant's benefit percentage. */ //TODO 26: Add the mapping between the column and the attribute //TODO 27: Add annotation custom datatype public Percentage getBenefitPercentage() { return benefitPercentage; } /** * Returns this restaurant's benefit availability policy. */ //TODO 28: Add the mapping between the column and the attribute //TODO 29: Add annotation custom datatype public BenefitAvailabilityPolicy getBenefitAvailabilityPolicy() { return benefitAvailabilityPolicy; } /** * Calculate the benefit eligible to this account for dining at this restaurant. * @param account the account that dined at this restaurant * @param dining a dining event that occurred * @return the benefit amount eligible for reward */ public MonetaryAmount calculateBenefitFor(Account account, Dining dining) { if (benefitAvailabilityPolicy.isBenefitAvailableFor(account, dining)) { return dining.getAmount().multiplyBy(benefitPercentage); } else { return MonetaryAmount.zero(); } } public String toString() { return "Number = '" + number + "', name = '" + name + "', benefitPercentage = " + benefitPercentage + ", benefitAvailabilityPolicy = " + benefitAvailabilityPolicy; } }