package com.cf.imes.module.system.dal.mysql.funds.advertisement;

import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.cf.imes.framework.mybatis.core.mapper.BaseMapperX;
import com.cf.imes.module.system.dal.dataobject.funds.advertisement.AdvertisementTaskDO;
import org.apache.ibatis.annotations.Mapper;

import java.util.List;

/**
 * 广告消费信息表 Mapper
 *
 * @author 晨丰科技
 */
@Mapper
public interface AdvertisementTaskMapper extends BaseMapperX<AdvertisementTaskDO> {

    default int updateToDeletedById(Long adId, Boolean deleted, Integer messageStatus) {
        return update(new LambdaUpdateWrapper<AdvertisementTaskDO>()
                .set(AdvertisementTaskDO::getDeleted, deleted)
                .set(AdvertisementTaskDO::getMessageStatus, messageStatus)
                .eq(AdvertisementTaskDO::getAdvertisementId, adId));
    }

    default List<String> selectIdByAdvertisementId(Long adId) {
        return selectList(new LambdaUpdateWrapper<AdvertisementTaskDO>()
                .eq(AdvertisementTaskDO::getAdvertisementId, adId))
                .stream()
                .map(AdvertisementTaskDO::getMessageId)
                .toList();
    }

    default AdvertisementTaskDO selectByMessageId(String messageId) {
        return selectOne(new LambdaUpdateWrapper<AdvertisementTaskDO>()
                .eq(AdvertisementTaskDO::getMessageId, messageId)
                .eq(AdvertisementTaskDO::getDeleted, Boolean.FALSE));
    }

    default int updateMessageStateByMessageId(String messageId, Boolean deleted, Integer messageStatus) {
        return update(new LambdaUpdateWrapper<AdvertisementTaskDO>()
                .set(AdvertisementTaskDO::getMessageStatus, messageStatus)
                .eq(AdvertisementTaskDO::getMessageId, messageId)
                .eq(AdvertisementTaskDO::getDeleted, deleted));
    }
}
