package com.cyksj.mapper;

import cn.hutool.core.date.DateTime;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.cyksj.model.entity.AccountDoubleVerifyRecord;
import com.cyksj.model.entity.GroupsTrips;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.Date;
import java.util.List;

/**
 * @author chan
 * @date 2022/9/27 4:24 PM
 */
public interface GroupsMapper extends BaseMapper<GroupsTrips> {
    @Update("update groups_trips set available_num = available_num - 1 where id = #{groupId} and available_num > 0")
    int decrAvailableNum(Long groupId);

    @Update("update groups_trips set available_num = available_num + 1 where id = #{groupId} and available_num < num")
    int incrAvailableNum(Long groupId);

    @Select("select count(*) from groups_trips where sku_id = #{skuId} and num = available_num")
	Integer selectEmptyNetflixTrips(Long skuId);

	List<AccountDoubleVerifyRecord> selectGPTDoubleVerifyTrips(Long goodsId);

	@Update("update groups_trips set available_num = (select count(*) from groups_relation where groups_id = #{groupsId} and status = 'none') where id = #{groupsId}")
	Integer updateAvailableNum(Long groupsId);

	List<GroupsTrips> getExpiryAccountGroups(@Param("nextBeginDay") DateTime nextBeginDay, @Param("list") List<Long> aiSkuIds);

	Long selectSameSpecItemGroupsByTime(@Param("groupsId") Long groupsId, @Param("skuId") Long skuId, @Param("expiryTime") Date expiryTime, @Param("betDay") DateTime betDay, @Param("extraNum") Integer extraNum);

	Long selectSameSpecEmptyGroups(Long skuId);

	Long selectMidJourneySameSpecItemGroups(@Param("groupsId") Long groupsId, @Param("skuId") Long skuId, @Param("expiryTime") Date expiryTime);

	Integer countExpiredNum(Long accountId);

	GroupsTrips selectTicketGroups(@Param("skuId") Long skuId, @Param("status") GroupsTrips.Status status, @Param("maxNum") Integer maxNum, @Param("ip") String ip, @Param("filterAccountTime") DateTime filterAccountTime);

	GroupsTrips selectCollegeStudentUserGptTicket(Long skuId);

	Long selectRandomGroupsTripsBySkuId(@Param("groupId") Long groupId, @Param("skuId") Long skuId, @Param("expiryTime") Date expiryTime);
}
