package com.zcloud.primeport.gatewayimpl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.zcloud.primeport.domain.gateway.VehicleBlackGateway;
import com.zcloud.primeport.domain.model.VehicleBlackE;
import com.zcloud.primeport.persistence.dataobject.VehicleBlackDO;
import com.zcloud.primeport.persistence.repository.VehicleBlackRepository;
import lombok.AllArgsConstructor;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;

/**
 * web-infrastructure
 *
 * @Author makejava
 * @Date 2026-03-05 11:33:26
 */
@Service
@AllArgsConstructor
public class VehicleBlackGatewayImpl implements VehicleBlackGateway {
    private final VehicleBlackRepository vehicleBlackRepository;

    @Override
    public Boolean add(VehicleBlackE vehicleBlackE) {
        VehicleBlackDO d = new VehicleBlackDO();
        BeanUtils.copyProperties(vehicleBlackE, d);
        vehicleBlackRepository.save(d);
        return true;
    }

    @Override
    public Boolean update(VehicleBlackE vehicleBlackE) {
        VehicleBlackDO d = new VehicleBlackDO();
        BeanUtils.copyProperties(vehicleBlackE, d);
        vehicleBlackRepository.updateById(d);
        return true;
    }

    @Override
    public Boolean deletedVehicleBlackById(Long id) {
        return vehicleBlackRepository.removeById(id);
    }

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

    @Override
    public void saveIfAbsent(String licenceNo,String vehicleType,String vehicleTypeName,String licenceType,String licenceTypeName) {
        List<VehicleBlackDO> licenceNoList = vehicleBlackRepository.list(new QueryWrapper<VehicleBlackDO>().eq("licence_no", licenceNo));
        if (licenceNoList.isEmpty()) {
            VehicleBlackDO d = new VehicleBlackDO();
            d.setLicenceNo(licenceNo);
            d.setLicenceType(licenceType);
            d.setLicenceTypeName(licenceTypeName);
            d.setVehicleType(vehicleType);
            d.setVehicleTypeName(vehicleTypeName);
            vehicleBlackRepository.save(d);
        }
    }
    @Override
    public VehicleBlackE getInfoById(Long id) {
        VehicleBlackE vehicleBlackE = new VehicleBlackE();
        BeanUtils.copyProperties(vehicleBlackRepository.getInfoById(id), vehicleBlackE);
        return vehicleBlackE;
    }


}

