package com.yuchen.saas.park.service.mapper.door.config;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.yuchen.saas.park.api.entity.door.config.DoorAccessControlConfigIssueTaskDetails;
import com.yuchen.saas.park.service.mapper.domain.task.DoorAccessControlConfigIssueTaskCondition;
import com.yuchen.saas.park.service.mapper.domain.task.DoorAccessControlConfigIssueTaskRO;
import lombok.val;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;

import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.Positive;
import java.util.List;
import java.util.Set;

import static java.util.Optional.ofNullable;

@Mapper
public interface DoorAccessControlConfigIssueTaskDetailsRepository extends BaseMapper<DoorAccessControlConfigIssueTaskDetails> {
    default List<DoorAccessControlConfigIssueTaskDetails> listUnprocessedByParentIds(@NotEmpty Set<@Positive Long> doorAccessControlConfigIssueTaskIds) {
        val o = Wrappers.<DoorAccessControlConfigIssueTaskDetails>lambdaQuery()
          .in(DoorAccessControlConfigIssueTaskDetails::getDoorAccessControlConfigIssueTaskId, doorAccessControlConfigIssueTaskIds)
          .isNull(DoorAccessControlConfigIssueTaskDetails::getProcessingStartTime);

        return ofNullable(this.selectList(o)).orElse(List.of());
    }

    IPage<DoorAccessControlConfigIssueTaskRO> pageByCondition(IPage<?> page, @Param("o") DoorAccessControlConfigIssueTaskCondition o);
}
