package com.backendsys.modules.ai.chat.entity;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonGetter;
import com.fasterxml.jackson.annotation.JsonSetter;
import lombok.Data;

import java.util.ArrayList;
import java.util.List;

@Data
@TableName("ai_chat_model")
public class ChatModel {
    @TableId(type = IdType.AUTO)
    private Long id;
    private Long parent_id;
    private String label;
    private String value;
    private String tag;
    @TableField(exist = false)
    private List<ChatModel> children;
    private Integer disabled;
    private Integer status;


    // 自定义getter方法用于JSON序列化
    @JsonGetter("disabled")
    public boolean getDisabledAsBoolean() {
        return disabled == 1;
    }

    // 自定义getter方法，确保children不会返回null
    @JsonGetter("children")
    public List<ChatModel> getChildren() {
        if (this.children == null) {
            return new ArrayList<>(); // 返回空数组
        }
        return this.children;
    }

    // 自定义setter方法，保持原有功能
    @JsonSetter("children")
    public void setChildren(List<ChatModel> children) {
        this.children = children;
    }
}
