package design.model; import com.fasterxml.jackson.annotation.JsonCreator; import java.util.ArrayList; import java.util.Date; import java.util.List; public abstract class League { private int id; private final String name; private final Date registrationDate; private final Date startDate; private final Date endDate; private final Golfer owner; private List schedule; private boolean completed; @JsonCreator protected League(int id, String name, Date registrationDate, Date startDate, Date endDate, Golfer owner, List schedule) { this.id = id; this.name = name; this.registrationDate = registrationDate; this.startDate = startDate; this.endDate = endDate; this.owner = owner; this.schedule = schedule; this.completed = false; } public League(String name, Date registrationDate, Date startDate, Date endDate, Golfer owner) { this.id = -1; this.name = name; this.registrationDate = registrationDate; this.startDate = startDate; this.endDate = endDate; this.owner = owner; this.schedule = new ArrayList<>(); this.completed = false; } public int getId() { return id; } public String getName() { return name; } public Date getRegistrationDate() { return registrationDate; } public Date getStartDate() { return startDate; } public Date getEndDate() { return endDate; } public Golfer getOwner() { return owner; } public List getSchedule() { return schedule; } public boolean isCompleted() { return completed; } public void addMatchToSchedule(Match match) { if(match.getDateScheduled().after(endDate)){ throw new IllegalArgumentException("Cannot create match after league has ended"); } schedule.add(match); } public void setId(int id) { assert this.id == -1; this.id = id; } public boolean isPlayable() { Date now = new Date(); return now.after(startDate) && now.before(endDate); } public void markCompleted(){ this.completed = true; } public abstract void recordPlay(Golfer player, Match match, Round round); public abstract void finalizeLeague(); }