package com.gzzm.lobster.artifact;

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

import java.util.List;

/**
 * ArtifactDao —— Artifact 持久化 / Artifact persistence.
 *
 * <p>status 枚举 thunwind 默认存 smallint ordinal，OQL 用参数绑定，不写字面量字符串。
 */
public abstract class ArtifactDao extends GeneralDao {

    @OQL("select a from Artifact a where a.artifactId=:1")
    public abstract Artifact getArtifact(String artifactId) throws Exception;

    @OQL("select a from Artifact a where a.threadId=:1 and a.status<>?2 order by a.updateTime desc")
    public abstract List<Artifact> listByThread(String threadId, ArtifactStatus excludeStatus) throws Exception;

    @OQL("select a from Artifact a where a.threadId=:1 and a.artifactType=?2 and a.status<>?3 order by a.updateTime desc")
    public abstract List<Artifact> listByThreadAndType(String threadId, ArtifactType type, ArtifactStatus excludeStatus) throws Exception;

    @OQL("select a from Artifact a where a.userId=:1 and a.status<>?2 order by a.updateTime desc limit :3,:4")
    public abstract List<Artifact> listByUser(String userId, ArtifactStatus excludeStatus, int offset, int limit) throws Exception;

    @OQLUpdate("update Artifact set status=?1 where artifactId=?2")
    public abstract int updateStatus(ArtifactStatus status, String artifactId) throws Exception;
}
