package com.yourname.premiumah.model;

import java.util.Locale;

public enum SortMode {
    NEWEST("Newest"),
    OLDEST("Oldest"),
    LOWEST_PRICE("Lowest Price"),
    HIGHEST_PRICE("Highest Price");

    private final String displayName;

    SortMode(String displayName) {
        this.displayName = displayName;
    }

    public String displayName() {
        return displayName;
    }

    public SortMode next() {
        SortMode[] values = values();
        return values[(ordinal() + 1) % values.length];
    }

    public static SortMode fromString(String value, SortMode fallback) {
        if (value == null || value.isBlank()) {
            return fallback;
        }
        try {
            return SortMode.valueOf(value.trim().toUpperCase(Locale.ROOT).replace('-', '_'));
        } catch (IllegalArgumentException ignored) {
            return fallback;
        }
    }
}
