package com.zcloud.domain.gatewayimpl;

import com.zcloud.domain.domain.gateway.ProjectTaskGateway;
import com.zcloud.domain.domain.model.ProjectTaskE;
import com.zcloud.domain.persistence.dataobject.ProjectTaskDO;
import com.zcloud.domain.persistence.repository.ProjectTaskRepository;
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;

/**
 * web-infrastructure
 *
 * @Author zhaokai
 * @Date 2026-01-29 11:28:41
 */
@Service
@AllArgsConstructor
public class ProjectTaskGatewayImpl implements ProjectTaskGateway {
    private final ProjectTaskRepository projectTaskRepository;

    @Override
    public Boolean add(ProjectTaskE projectTaskE) {
        if(StringUtils.isEmpty(projectTaskE.getProjectTaskId())){
            projectTaskE.setProjectTaskId(Tools.get32UUID());
        }
        ProjectTaskDO d = new ProjectTaskDO();
        BeanUtils.copyProperties(projectTaskE, d);
        projectTaskRepository.save(d);
        projectTaskE.setId(d.getId());
        return true;
    }

    @Override
    public Boolean update(ProjectTaskE projectTaskE) {
        ProjectTaskDO d = new ProjectTaskDO();
        BeanUtils.copyProperties(projectTaskE, d);
        projectTaskRepository.updateById(d);
        return true;
    }

    @Override
    public Boolean deletedProjectTaskById(Long id) {
        return projectTaskRepository.removeById(id);
    }

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

