92 lines
2.7 KiB
Java
92 lines
2.7 KiB
Java
package model;
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.List;
|
|
|
|
/**
|
|
* Facade for the model layer. Manages the lifecycle of one repair session at a time
|
|
* and delegates all operations to the current {@link ActiveRepair}.
|
|
*
|
|
* <p>Observers registered via {@link #addObserver(RepairOrderObserver)} are
|
|
* automatically forwarded to every new repair session that is started.</p>
|
|
*/
|
|
public class RepairShop {
|
|
|
|
private ActiveRepair currentRepair;
|
|
private final List<RepairOrderObserver> observers = new ArrayList<>();
|
|
private DiscountStrategy discountStrategy = new NoDiscount();
|
|
|
|
/**
|
|
* Creates a new RepairShop ready to accept repair sessions.
|
|
*/
|
|
public RepairShop() {
|
|
}
|
|
|
|
/**
|
|
* Registers an observer to be notified whenever a repair order changes.
|
|
* The observer is passed to every repair session started after this call.
|
|
*
|
|
* @param observer The observer to register.
|
|
*/
|
|
public void addObserver(RepairOrderObserver observer) {
|
|
observers.add(observer);
|
|
}
|
|
|
|
/**
|
|
* Sets the discount strategy to apply to each new repair session's total.
|
|
*
|
|
* @param strategy The discount strategy; must not be {@code null}.
|
|
*/
|
|
public void setDiscountStrategy(DiscountStrategy strategy) {
|
|
this.discountStrategy = strategy;
|
|
}
|
|
|
|
/**
|
|
* Starts a new repair session, discarding any previously active session.
|
|
*/
|
|
public void startRepair() {
|
|
currentRepair = new ActiveRepair();
|
|
for (RepairOrderObserver observer : observers) {
|
|
currentRepair.addObserver(observer);
|
|
}
|
|
currentRepair.setDiscountStrategy(discountStrategy);
|
|
}
|
|
|
|
/**
|
|
* Registers the bike that will be worked on during the current repair session.
|
|
*
|
|
* @param bike The {@link BikeDTO} of the bike to register.
|
|
*/
|
|
public void registerBike(BikeDTO bike) {
|
|
currentRepair.registerBike(bike);
|
|
}
|
|
|
|
/**
|
|
* Adds a repair task to the current session and returns the updated running total.
|
|
*
|
|
* @param task The {@link TaskDTO} of the task to add.
|
|
* @return The running total after the task has been added.
|
|
*/
|
|
public Amount addTask(TaskDTO task) {
|
|
return currentRepair.addTask(task);
|
|
}
|
|
|
|
/**
|
|
* Records the mechanic's diagnostic notes for the current repair session.
|
|
*
|
|
* @param report The diagnostic report text entered by the mechanic.
|
|
*/
|
|
public void enterDiagnosticReport(String report) {
|
|
currentRepair.enterDiagnosticReport(report);
|
|
}
|
|
|
|
/**
|
|
* Ends the current repair session and returns the completed repair order.
|
|
*
|
|
* @return The {@link RepairOrder} for the finished repair.
|
|
*/
|
|
public RepairOrder endRepair() {
|
|
return currentRepair.endRepair();
|
|
}
|
|
}
|