package com.zcloud.basic.info.gatewayimpl;

import com.alibaba.cloud.commons.lang.StringUtils;
import com.zcloud.basic.info.domain.gateway.ProblemFeedbackGateway;
import com.zcloud.basic.info.domain.model.ProblemFeedbackE;
import com.zcloud.basic.info.persistence.dataobject.ProblemFeedbackDO;
import com.zcloud.basic.info.persistence.repository.ProblemFeedbackRepository;
import com.zcloud.gbscommon.utils.UuidUtil;
import lombok.AllArgsConstructor;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import java.util.Collections;

/**
 * web-infrastructure
 *
 * @Author SondonYong
 * @Date 2025-12-06 11:26:34
 */
@Service
@AllArgsConstructor
public class ProblemFeedbackGatewayImpl implements ProblemFeedbackGateway {
    private final ProblemFeedbackRepository problemFeedbackRepository;

    @Override
    public Boolean add(ProblemFeedbackE problemFeedbackE) {
        ProblemFeedbackDO d = new ProblemFeedbackDO();
        BeanUtils.copyProperties(problemFeedbackE, d);
        if(StringUtils.isEmpty(d.getProblemId())){
            d.setProblemId(UuidUtil.get32UUID());
        }
        problemFeedbackRepository.save(d);
        return true;
    }

    @Override
    public Boolean update(ProblemFeedbackE problemFeedbackE) {
        ProblemFeedbackDO d = new ProblemFeedbackDO();
        BeanUtils.copyProperties(problemFeedbackE, d);
        problemFeedbackRepository.updateById(d);
        return true;
    }

    @Override
    public Boolean deletedProblemFeedbackById(Long id) {
        return problemFeedbackRepository.removeById(id);
    }

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

