package com.zcloud.personnel.positioning.gatewayimpl;

import com.zcloud.personnel.positioning.domain.gateway.AreaGateway;
import com.zcloud.personnel.positioning.domain.model.AreaE;
import com.zcloud.personnel.positioning.persistence.dataobject.AreaDO;
import com.zcloud.personnel.positioning.persistence.repository.AreaRepository;
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 AreaGatewayImpl implements AreaGateway {
    private final AreaRepository areaRepository;

    @Override
    public Boolean add(AreaE areaE) {
        AreaDO dataObject = new AreaDO();
        BeanUtils.copyProperties(areaE, dataObject);
        areaRepository.save(dataObject);
        return true;
    }

    @Override
    public Boolean update(AreaE areaE) {
        AreaDO dataObject = new AreaDO();
        BeanUtils.copyProperties(areaE, dataObject);
        areaRepository.updateById(dataObject);
        return true;
    }

    @Override
    public Boolean deletedAreaById(Long id) {
        return areaRepository.removeById(id);
    }

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