package com.zcloud.domain.gatewayimpl;

import com.jjb.saas.framework.auth.utils.AuthContext;
import com.zcloud.domain.domain.gateway.DomainDepartmentGateway;
import com.zcloud.domain.domain.model.DomainDepartmentE;
import com.zcloud.domain.persistence.dataobject.DomainDepartmentDO;
import com.zcloud.domain.persistence.repository.DomainDepartmentRepository;
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.Arrays;
import java.util.Collections;

/**
 * web-infrastructure
 *
 * @Author zhaokai
 * @Date 2026-01-27 11:28:51
 */
@Service
@AllArgsConstructor
public class DomainDepartmentGatewayImpl implements DomainDepartmentGateway {
    private final DomainDepartmentRepository domainDepartmentRepository;

    @Override
    public Boolean add(DomainDepartmentE domainDepartmentE) {
        if(StringUtils.isEmpty(domainDepartmentE.getDomainDepartmentId())){
            domainDepartmentE.setDomainDepartmentId(Tools.get32UUID());
        }
        DomainDepartmentDO d = new DomainDepartmentDO();
        BeanUtils.copyProperties(domainDepartmentE, d);
        domainDepartmentRepository.save(d);
        return true;
    }

    @Override
    public Boolean update(DomainDepartmentE domainDepartmentE) {
        DomainDepartmentDO d = new DomainDepartmentDO();
        BeanUtils.copyProperties(domainDepartmentE, d);
        domainDepartmentRepository.updateById(d);
        return true;
    }

    @Override
    public Boolean deletedDomainDepartmentById(Long id) {
        return domainDepartmentRepository.removeById(id);
    }

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

