package com.zcloud.primeport.gatewayimpl;

import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.zcloud.primeport.domain.gateway.VehicleAuditGateway;
import com.zcloud.primeport.domain.model.VehicleAuditE;
import com.zcloud.primeport.persistence.dataobject.VehicleAuditDO;
import com.zcloud.primeport.persistence.repository.VehicleAuditRepository;
import lombok.AllArgsConstructor;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import java.util.Collections;

/**
 * web-infrastructure
 *
 * @Author makejava
 * @Date 2026-03-05 11:33:25
 */
@Service
@AllArgsConstructor
public class VehicleAuditGatewayImpl implements VehicleAuditGateway {
    private final VehicleAuditRepository vehicleAuditRepository;

    @Override
    public Boolean add(VehicleAuditE vehicleAuditE) {
        VehicleAuditDO d = new VehicleAuditDO();
        BeanUtils.copyProperties(vehicleAuditE, d);
        vehicleAuditRepository.save(d);
        vehicleAuditE.setId(d.getId());
        return true;
    }

    @Override
    public Boolean update(VehicleAuditE vehicleAuditE) {
        VehicleAuditDO d = new VehicleAuditDO();
        BeanUtils.copyProperties(vehicleAuditE, d);
        vehicleAuditRepository.updateById(d);
        return true;
    }

    @Override
    public Boolean deletedVehicleAuditById(Long id) {
        return vehicleAuditRepository.removeById(id);
    }

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

    @Override
    public void deletedVehicleAuditByApplyId(Long id) {
        UpdateWrapper<VehicleAuditDO> objectUpdateWrapper = new UpdateWrapper<>();
        objectUpdateWrapper.eq("vehicle_apply_id",id);
        vehicleAuditRepository.remove(objectUpdateWrapper);
    }
}

