package com.zcloud.personnel.positioning.gatewayimpl;

import com.zcloud.personnel.positioning.domain.gateway.TerminalGateway;
import com.zcloud.personnel.positioning.domain.model.TerminalE;
import com.zcloud.personnel.positioning.persistence.dataobject.TerminalDO;
import com.zcloud.personnel.positioning.persistence.repository.TerminalRepository;
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 TerminalGatewayImpl implements TerminalGateway {
    private final TerminalRepository terminalRepository;

    @Override
    public Boolean add(TerminalE terminalE) {
        TerminalDO dataObject = new TerminalDO();
        BeanUtils.copyProperties(terminalE, dataObject);
        terminalRepository.save(dataObject);
        return true;
    }

    @Override
    public Boolean update(TerminalE terminalE) {
        TerminalDO dataObject = new TerminalDO();
        BeanUtils.copyProperties(terminalE, dataObject);
        terminalRepository.updateById(dataObject);
        return true;
    }

    @Override
    public Boolean deletedTerminalById(Long id) {
        return terminalRepository.removeById(id);
    }

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