package com.yaoai.domain.mapper;

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

import java.util.List;

@Mapper
public interface GlobalAssetMapper extends BaseMapper<GlobalAsset> {

    default List<GlobalAsset> findByTenantAndType(Long tenantId, String assetType, String libraryType) {
        var query = Wrappers.<GlobalAsset>lambdaQuery()
                .eq(GlobalAsset::getTenantId, tenantId)
                .eq(assetType != null && !assetType.isBlank(), GlobalAsset::getAssetType, assetType)
                .eq(libraryType != null && !libraryType.isBlank(), GlobalAsset::getLibraryType, libraryType)
                .orderByDesc(GlobalAsset::getCreatedAt);
        return selectList(query);
    }
}
