package cn.axzo.msg.center.utils;

import cn.axzo.msg.center.domain.entity.PendingMessageRecord;
import com.baomidou.mybatisplus.core.toolkit.support.SFunction;
import com.google.common.collect.ImmutableMap;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;

/**
 * 排序字段的解析管理
 *
 * @author cold_blade
 * @date 2023/10/7
 * @version 1.0
 */
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public final class OrderFieldParseUtil {

    private static final ImmutableMap<String, SFunction<PendingMessageRecord, ?>>
            PENDING_MESSAGE_RECORD_ORDER_FIELD = ImmutableMap.<String, SFunction<PendingMessageRecord, ?>>builder()
            .put("createTimestamp", PendingMessageRecord::getCreateAt)
            .put("updateTimestamp", PendingMessageRecord::getUpdateAt)
            .build();

    public static boolean containsPendingMessageRecordOrderField(String orderField) {
        return PENDING_MESSAGE_RECORD_ORDER_FIELD.containsKey(orderField);
    }

    public static SFunction<PendingMessageRecord, ?> parsePendingMessageRecordOrderField(String orderField) {
        return PENDING_MESSAGE_RECORD_ORDER_FIELD.get(orderField);
    }
}
