/*
 * Copyright 2017-2025 noear.org and authors
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      https://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.noear.solon.ai.chat.resource;

import org.noear.solon.ai.chat.content.ResourceBlock;
import org.noear.solon.ai.chat.content.TextBlock;

import java.util.LinkedHashMap;
import java.util.List;
import java.util.ArrayList;
import java.util.Map;

/**
 * 资源包
 *
 * @author noear
 * @since 3.9.2
 */
public class ResourcePack {
    private final List<ResourceBlock> resources = new ArrayList<>();
    private final Map<String, Object> metas = new LinkedHashMap<>();

    public ResourcePack() {
        //用于反序列化
    }

    public ResourcePack(List<ResourceBlock> resources) {
        this.resources.addAll(resources);
    }

    public ResourcePack addText(String text) {
        resources.add(TextBlock.of(text));
        return this;
    }

    public ResourcePack addResource(ResourceBlock resource) {
        resources.add(resource);
        return this;
    }

    public Map<String, Object> metas() {
        return metas;
    }

    public String getContent() {
        if (resources.isEmpty()) {
            return null;
        } else {
            return resources.get(0).getContent();
        }
    }

    public int size() {
        return resources.size();
    }

    public List<ResourceBlock> getResources() {
        return resources;
    }

    @Override
    public String toString() {
        return resources.toString();
    }
}