package com.zcloud.basic.info.gatewayimpl;

import com.jjb.saas.framework.auth.utils.AuthContext;
import com.zcloud.basic.info.domain.gateway.UserExpandInfoGateway;
import com.zcloud.basic.info.domain.model.UserExpandInfoE;
import com.zcloud.basic.info.persistence.dataobject.UserExpandInfoDO;
import com.zcloud.basic.info.persistence.repository.UserExpandInfoRepository;
import com.zcloud.gbscommon.utils.Tools;
import lombok.AllArgsConstructor;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.Collections;

/**
 * web-infrastructure
 *
 * @Author zhaokai
 * @Date 2026-01-05 14:12:19
 */
@Service
@AllArgsConstructor
public class UserExpandInfoGatewayImpl implements UserExpandInfoGateway {
    private final UserExpandInfoRepository userExpandInfoRepository;

    @Override
    public Boolean add(UserExpandInfoE userExpandInfoE) {
        if(StringUtils.isEmpty(userExpandInfoE.getUserExpandInfoId())){
            userExpandInfoE.setUserExpandInfoId(Tools.get32UUID());
        }

        UserExpandInfoDO d = new UserExpandInfoDO();
        BeanUtils.copyProperties(userExpandInfoE, d);
        userExpandInfoRepository.save(d);
        return true;
    }

    @Override
    public Boolean update(UserExpandInfoE userExpandInfoE) {
        UserExpandInfoDO d = new UserExpandInfoDO();
        BeanUtils.copyProperties(userExpandInfoE, d);
        userExpandInfoRepository.updateById(d);
        return true;
    }

    @Override
    public Boolean deletedUserExpandInfoById(Long id) {
        return userExpandInfoRepository.removeById(id);
    }

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

