package com.sikey.wa04.business.infrastructure.adapter.dao;

import cn.hutool.core.collection.CollectionUtil;
import com.sikey.wa04.business.domain.adapter.ChildFenceAdapter;
import com.sikey.wa04.business.domain.entity.ChildFence;
import com.sikey.wa04.business.infrastructure.convert.ChildFenceConvert;
import com.sikey.wa04.business.infrastructure.dto.model.ChildFenceModel;
import com.sikey.wa04.business.infrastructure.repository.ChildFenceRepository;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.util.Collections;
import java.util.List;

/**
 * @Author: qin
 * @Date: 2025/3/17
 * @Description: 儿童围栏
 */
@Slf4j
@Component
public class ChildFenceAdapterImpl implements ChildFenceAdapter {

    @Resource
    private ChildFenceRepository childFenceRepository;

    /**
     * 获取儿童围栏
     *
     * @param childId 儿童id
     * @param state   状态
     * @return
     */
    @Override
    public List<ChildFence> findNotDisableByChildrenId(String childId, Boolean state) {
        List<ChildFenceModel> findByChildIdState = childFenceRepository.findNotDisableByChildIdAndState(childId, state);
        if (CollectionUtil.isEmpty(findByChildIdState)) {
            return Collections.emptyList();
        }

        return ChildFenceConvert.INSTANCE.convert(findByChildIdState);
    }
}
