package com.yhy.module.core.dal.mysql.workbench;

import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import com.yhy.module.core.dal.dataobject.workbench.SyncBindingDO;
import java.util.List;
import org.apache.ibatis.annotations.Mapper;

/**
 * 同步绑定关系 Mapper
 *
 * @author yhy
 */
@Mapper
public interface SyncBindingMapper extends BaseMapperX<SyncBindingDO> {

    /**
     * 根据同步库ID查询绑定列表
     */
    default List<SyncBindingDO> selectListBySyncLibraryId(Long syncLibraryId) {
        return selectList(new LambdaQueryWrapperX<SyncBindingDO>()
                .eq(SyncBindingDO::getSyncLibraryId, syncLibraryId));
    }

    /**
     * 根据多个同步库ID批量查询绑定列表
     */
    default List<SyncBindingDO> selectListBySyncLibraryIds(List<Long> syncLibraryIds) {
        return selectList(new LambdaQueryWrapperX<SyncBindingDO>()
                .in(SyncBindingDO::getSyncLibraryId, syncLibraryIds));
    }

    /**
     * 根据分部分项ID查询绑定
     */
    default SyncBindingDO selectByDivisionId(Long divisionId) {
        return selectOne(new LambdaQueryWrapperX<SyncBindingDO>()
                .eq(SyncBindingDO::getDivisionId, divisionId));
    }

    /**
     * 根据单位工程ID查询绑定列表
     */
    default List<SyncBindingDO> selectListByCompileTreeId(Long compileTreeId) {
        return selectList(new LambdaQueryWrapperX<SyncBindingDO>()
                .eq(SyncBindingDO::getCompileTreeId, compileTreeId));
    }

    /**
     * 根据同步库ID统计绑定数量
     */
    default Long selectCountBySyncLibraryId(Long syncLibraryId) {
        return selectCount(new LambdaQueryWrapperX<SyncBindingDO>()
                .eq(SyncBindingDO::getSyncLibraryId, syncLibraryId));
    }

    /**
     * 根据分部分项ID删除绑定
     */
    default int deleteByDivisionId(Long divisionId) {
        return delete(new LambdaQueryWrapperX<SyncBindingDO>()
                .eq(SyncBindingDO::getDivisionId, divisionId));
    }

    /**
     * 根据同步库ID删除所有绑定
     */
    default int deleteBySyncLibraryId(Long syncLibraryId) {
        return delete(new LambdaQueryWrapperX<SyncBindingDO>()
                .eq(SyncBindingDO::getSyncLibraryId, syncLibraryId));
    }
}
