package com.yaoai.domain.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.yaoai.domain.entity.ScriptUnderstanding;
import org.apache.ibatis.annotations.Mapper;

@Mapper
public interface ScriptUnderstandingMapper extends BaseMapper<ScriptUnderstanding> {

    default ScriptUnderstanding findLatestByProject(Long projectId, Long tenantId) {
        return selectOne(Wrappers.<ScriptUnderstanding>lambdaQuery()
                .eq(ScriptUnderstanding::getProjectId, projectId)
                .eq(ScriptUnderstanding::getTenantId, tenantId)
                .orderByDesc(ScriptUnderstanding::getCreatedAt)
                .last("LIMIT 1"));
    }
}
