package com.zcloud.basic.info.gatewayimpl;

import com.zcloud.basic.info.domain.gateway.UserChangeRecordGateway;
import com.zcloud.basic.info.domain.model.UserChangeRecordE;
import com.zcloud.basic.info.persistence.dataobject.UserChangeRecordDO;
import com.zcloud.basic.info.persistence.repository.UserChangeRecordRepository;
import com.zcloud.gbscommon.utils.Tools;
import lombok.AllArgsConstructor;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import java.util.Collections;

/**
 * web-infrastructure
 *
 * @Author SondonYong
 * @Date 2025-12-02 14:08:19
 */
@Service
@AllArgsConstructor
public class UserChangeRecordGatewayImpl implements UserChangeRecordGateway {
    private final UserChangeRecordRepository userChangeRecordRepository;

    @Override
    public Boolean add(UserChangeRecordE userChangeRecordE) {
        if(StringUtils.isEmpty(userChangeRecordE.getUserChangeRecordId())){
            userChangeRecordE.setUserChangeRecordId(Tools.get32UUID());
        }
        UserChangeRecordDO d = new UserChangeRecordDO();
        BeanUtils.copyProperties(userChangeRecordE, d);
        userChangeRecordRepository.save(d);
        userChangeRecordE.setId(d.getId());
        return true;
    }

    @Override
    public Boolean update(UserChangeRecordE userChangeRecordE) {
        UserChangeRecordDO d = new UserChangeRecordDO();
        BeanUtils.copyProperties(userChangeRecordE, d);
        userChangeRecordRepository.updateById(d);
        return true;
    }

    @Override
    public Boolean deletedUserChangeRecordById(Long id) {
        return userChangeRecordRepository.removeById(id);
    }

    @Override
    public Boolean deletedUserChangeRecordByIds(Long[] ids) {
        return userChangeRecordRepository.removeByIds(Collections.singletonList(ids));
    }
}

