package com.lideeyunji.tool.framework.ai.chat;

import com.lideeyunji.tool.framework.yunji.utils.FuncBase;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Arrays;
import java.util.Optional;


@Getter
@AllArgsConstructor
public enum ChatMessageType {
    SYSTEM("system"),
    USER("user"),
    ASSISTANT("assistant"),
    TOOL("tool"),
    ;

    private final String role;

    public static ChatMessageType getByRole(String role) {
        // 使用流来查找匹配的
        Optional<ChatMessageType> matchingEnum = Arrays.stream(ChatMessageType.values())
                .filter(chatMessageType -> FuncBase.equals(chatMessageType.getRole(), role))
                .findFirst(); // findFirst()会返回第一个匹配的元素，或者如果找不到则返回一个空的Optional
        // 检查是否找到了匹配的枚举项
        if (matchingEnum.isPresent()) {
            return matchingEnum.get();
        }
        return null;

    }
}
