package com.yaoai.domain.mapper;

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

import java.util.List;
import java.util.Optional;

@Mapper
public interface ProjectMapper extends BaseMapper<Project> {

    default List<Project> findByTenant(Long tenantId) {
        return selectList(Wrappers.<Project>lambdaQuery()
                .eq(Project::getTenantId, tenantId)
                .isNull(Project::getDeletedAt)
                .orderByDesc(Project::getCreatedAt));
    }

    default Optional<Project> findActiveById(Long id, Long tenantId) {
        return Optional.ofNullable(selectOne(Wrappers.<Project>lambdaQuery()
                .eq(Project::getId, id)
                .eq(Project::getTenantId, tenantId)
                .isNull(Project::getDeletedAt)));
    }
}
