package com.ycwl.basic.puzzle.fill.enums;

import lombok.Getter;

/**
 * 素材排序策略枚举
 */
@Getter
public enum SortStrategy {

    /**
     * 最新创建(按create_time DESC)
     */
    LATEST("LATEST", "最新创建"),

    /**
     * 最早创建(按create_time ASC)
     */
    EARLIEST("EARLIEST", "最早创建"),

    /**
     * 分数降序(按score DESC,需要source表有score字段)
     */
    SCORE_DESC("SCORE_DESC", "分数降序"),

    /**
     * 优先已购买(按is_buy DESC, create_time DESC)
     */
    PURCHASED_FIRST("PURCHASED_FIRST", "优先已购买");

    private final String code;
    private final String description;

    SortStrategy(String code, String description) {
        this.code = code;
        this.description = description;
    }

    /**
     * 根据code获取枚举
     */
    public static SortStrategy fromCode(String code) {
        for (SortStrategy strategy : values()) {
            if (strategy.code.equals(code)) {
                return strategy;
            }
        }
        return LATEST; // 默认返回最新
    }
}
