package com.zcloud.personnel.positioning.gatewayimpl;

import com.zcloud.personnel.positioning.domain.gateway.FenceGateway;
import com.zcloud.personnel.positioning.domain.model.FenceE;
import com.zcloud.personnel.positioning.persistence.dataobject.FenceDO;
import com.zcloud.personnel.positioning.persistence.repository.FenceRepository;
import lombok.AllArgsConstructor;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import java.util.Arrays;

/**
 * web-infrastructure
 *
 * @Author fangjiakai
 * @Date 2026-07-07
 */
@Service
@AllArgsConstructor
public class FenceGatewayImpl implements FenceGateway {
    private final FenceRepository fenceRepository;

    @Override
    public Boolean add(FenceE fenceE) {
        FenceDO dataObject = new FenceDO();
        BeanUtils.copyProperties(fenceE, dataObject);
        fenceRepository.save(dataObject);
        return true;
    }

    @Override
    public Boolean update(FenceE fenceE) {
        FenceDO dataObject = new FenceDO();
        BeanUtils.copyProperties(fenceE, dataObject);
        fenceRepository.updateById(dataObject);
        return true;
    }

    @Override
    public Boolean deletedFenceById(Long id) {
        return fenceRepository.removeById(id);
    }

    @Override
    public Boolean deletedFenceByIds(Long[] ids) {
        return fenceRepository.removeByIds(Arrays.asList(ids));
    }
}
