package library.step5;

/**
 * Tipo de socio de la biblioteca. Paso 5 · Replace Conditional with
 * Polymorphism: cada constante hace override de fineFor con su propia regla,
 * así que ya no hay switch. Un tipo de socio nuevo es una constante nueva.
 */
public enum MemberType {
    STUDENT {
        @Override
        int fineFor(Loan loan) {
            int charged = Math.max(loan.daysLate() - GRACE_DAYS, 0);
            return Math.min(charged * loan.kind().dailyRate(), CAP);
        }
    },
    TEACHER {
        @Override
        int fineFor(Loan loan) {
            return loan.kind() == ItemKind.DVD ? loan.daysLate() * loan.kind().dailyRate() : 0;
        }
    },
    VISITOR {
        @Override
        int fineFor(Loan loan) {
            return loan.daysLate() * loan.kind().dailyRate() * 2;
        }
    };

    private static final int GRACE_DAYS = 2;
    private static final int CAP = 1000;     // tope por préstamo, en céntimos

    /** Multa de un préstamo para este tipo de socio, en céntimos. */
    abstract int fineFor(Loan loan);
}
