package com.flowing.light.board.tools;

import android.content.Context;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

public class FileUtils {
    /**
     * 读取JSON并返回List<CategoryData>（关键：类型匹配）
     */
    public static List<CategoryData> readCategoryJsonFromAssets(Context context, String fileName) {
        List<CategoryData> dataList = new ArrayList<>();
        if (context == null) {
            return dataList;
        }
        try (InputStream is = context.getAssets().open(fileName);
             InputStreamReader isr = new InputStreamReader(is)) {
            Gson gson = new Gson();
            dataList = gson.fromJson(isr, new TypeToken<List<CategoryData>>() {}.getType());
        } catch (Exception e) {
            e.printStackTrace();
        }
        return dataList != null ? dataList : new ArrayList<>();
    }
}