package com.zcloud.personnel.positioning.gatewayimpl;

import com.zcloud.personnel.positioning.domain.gateway.OpenapiConfigGateway;
import com.zcloud.personnel.positioning.domain.model.OpenapiConfigE;
import com.zcloud.personnel.positioning.persistence.dataobject.OpenapiConfigDO;
import com.zcloud.personnel.positioning.persistence.repository.OpenapiConfigRepository;
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 OpenapiConfigGatewayImpl implements OpenapiConfigGateway {
    private final OpenapiConfigRepository openapiConfigRepository;

    @Override
    public Boolean add(OpenapiConfigE openapiConfigE) {
        OpenapiConfigDO dataObject = new OpenapiConfigDO();
        BeanUtils.copyProperties(openapiConfigE, dataObject);
        openapiConfigRepository.save(dataObject);
        return true;
    }

    @Override
    public Boolean update(OpenapiConfigE openapiConfigE) {
        OpenapiConfigDO dataObject = new OpenapiConfigDO();
        BeanUtils.copyProperties(openapiConfigE, dataObject);
        openapiConfigRepository.updateById(dataObject);
        return true;
    }

    @Override
    public Boolean deletedOpenapiConfigById(Long id) {
        return openapiConfigRepository.removeById(id);
    }

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