
package dev.sonpx.loyalty.mcp.criteria;


import dev.sonpx.loyalty.mcp.filter.RangeFilter;
import dev.sonpx.loyalty.mcp.filter.StringFilter;
import java.net.URLDecoder;
import java.nio.charset.StandardCharsets;
import java.time.Instant;
import lombok.Data;

/**
 * Created by SonPhung on Monday, 20-Jul-2026
 */
@Data
public abstract class AbstractFwCriteria {

    protected StringFilter status;
    protected RangeFilter<Instant> lastUpdateDate;

    // for search text
    protected String search;
    protected String searchComponent;

    //Handle URL-encoded search text (e.g. "%20", "%23") received from UI
    //e.g: search=tìm%20kiếm -> tìm kiếm
    public void setSearch(String search) {
        try {
            this.search = search == null ? null : URLDecoder.decode(search, StandardCharsets.UTF_8);
        } catch (IllegalArgumentException e) {
            this.search = search;
        }
    }
}
