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

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.yuchen.saas.park.api.commons.domain.DoorAccessControlConfigTarget;
import com.yuchen.saas.park.api.commons.enums.DoorAccessControlConfigType;
import com.yuchen.saas.park.api.entity.door.config.DoorAccessControlConfigIssueTask;
import lombok.val;
import org.apache.ibatis.annotations.Mapper;

import javax.validation.constraints.Positive;
import java.util.List;
import java.util.Optional;

@Mapper
public interface DoorAccessControlConfigIssuedDetailsRepository extends BaseMapper<DoorAccessControlConfigIssueTask> {
    default Optional<DoorAccessControlConfigIssueTask> getByConfigId(DoorAccessControlConfigType type, @Positive long configId) {
        val o = Wrappers.<DoorAccessControlConfigIssueTask>lambdaQuery()
          .eq(DoorAccessControlConfigIssueTask::getType, type.getCode())
          .eq(DoorAccessControlConfigIssueTask::getConfigId, configId);

        return Optional.ofNullable(this.selectOne(o));
    }

    default List<DoorAccessControlConfigIssueTask> listByTarget(DoorAccessControlConfigTarget target) {
        val o = Wrappers.<DoorAccessControlConfigIssueTask>lambdaQuery()
          .eq(DoorAccessControlConfigIssueTask::getUserId, target.getUserId())
          .eq(DoorAccessControlConfigIssueTask::getDoorAccessControlId, target.getDoorAccessControlId());

        return this.selectList(o);
    }
}
