package cn.iocoder.byzs.module.ai.dal.mysql.video;

import cn.iocoder.byzs.framework.common.pojo.PageResult;
import cn.iocoder.byzs.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.byzs.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.byzs.module.ai.controller.admin.video.vo.AiVideoPageReqVO;
import cn.iocoder.byzs.module.ai.controller.admin.video.vo.AiVideoPublicPageReqVO;
import cn.iocoder.byzs.module.ai.dal.dataobject.video.AiVideoDO;
import org.apache.ibatis.annotations.Mapper;

import java.util.List;

/**
 * AI 绘图 Mapper
 *
 * @author fansili
 */
@Mapper
public interface AiVideoMapper extends BaseMapperX<AiVideoDO> {

    default AiVideoDO selectByTaskId(String taskId) {
        return selectOne(AiVideoDO::getTaskId, taskId);
    }

    default PageResult<AiVideoDO> selectPage(AiVideoPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<AiVideoDO>()
                .eqIfPresent(AiVideoDO::getUserId, reqVO.getUserId())
                .eqIfPresent(AiVideoDO::getPlatform, reqVO.getPlatform())
                .eqIfPresent(AiVideoDO::getStatus, reqVO.getStatus())
                .eqIfPresent(AiVideoDO::getPublicStatus, reqVO.getPublicStatus())
                .betweenIfPresent(AiVideoDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(AiVideoDO::getId));
    }

    default PageResult<AiVideoDO> selectPageMy(Long userId, AiVideoPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<AiVideoDO>()
                .likeIfPresent(AiVideoDO::getPrompt, reqVO.getPrompt())
                // 情况一：公开
                .eq(Boolean.TRUE.equals(reqVO.getPublicStatus()), AiVideoDO::getPublicStatus, reqVO.getPublicStatus())
                // 情况二：私有
                .eq(Boolean.FALSE.equals(reqVO.getPublicStatus()), AiVideoDO::getUserId, userId)
                .orderByDesc(AiVideoDO::getId));
    }

    default PageResult<AiVideoDO> selectPage(AiVideoPublicPageReqVO pageReqVO) {
        return selectPage(pageReqVO, new LambdaQueryWrapperX<AiVideoDO>()
                .eqIfPresent(AiVideoDO::getPublicStatus, Boolean.TRUE)
                .likeIfPresent(AiVideoDO::getPrompt, pageReqVO.getPrompt())
                .orderByDesc(AiVideoDO::getId));
    }

    default List<AiVideoDO> selectListByStatusAndPlatform(Integer status, String platform) {
        return selectList(AiVideoDO::getStatus, status,
                AiVideoDO::getPlatform, platform);
    }

}
