package com.gzzm.lobster.llm;

import com.gzzm.lobster.common.ModelServiceTier;
import net.cyan.thunwind.annotation.OQL;
import net.cyan.thunwind.annotation.OQLUpdate;
import net.cyan.thunwind.dao.GeneralDao;

import java.util.List;

/**
 * ModelProfileDao —— 模型配置持久化 / ModelProfile persistence.
 */
public abstract class ModelProfileDao extends GeneralDao {

    @OQL("select p from ModelProfile p where p.modelId=:1")
    public abstract ModelProfile getProfile(String modelId) throws Exception;

    @OQL("select p from ModelProfile p where p.enabled=1 order by p.serviceTier asc, p.priority desc, p.modelId asc")
    public abstract List<ModelProfile> listEnabled() throws Exception;

    @OQL("select p from ModelProfile p where p.enabled=1 and p.serviceTier=?1 order by p.priority desc, p.modelId asc")
    public abstract List<ModelProfile> listByTier(ModelServiceTier tier) throws Exception;

    @OQL("select p from ModelProfile p where p.enabled=1 and p.provider=?1 order by p.priority desc, p.modelId asc")
    public abstract List<ModelProfile> listByProvider(ModelProvider provider) throws Exception;

    @OQL("select p from ModelProfile p order by p.serviceTier asc, p.priority desc, p.modelId asc limit :1,:2")
    public abstract List<ModelProfile> listAll(int offset, int limit) throws Exception;

    @OQL("select count(p) from ModelProfile p")
    public abstract long countAll() throws Exception;

    @OQLUpdate("delete from ModelProfile where modelId=?1")
    public abstract int deleteById(String modelId) throws Exception;
}
