package com.zcloud.primeport.gatewayimpl;

import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.zcloud.primeport.domain.gateway.VehicleViolationsGateway;
import com.zcloud.primeport.domain.model.VehicleViolationsE;
import com.zcloud.primeport.persistence.dataobject.VehicleViolationsDO;
import com.zcloud.primeport.persistence.repository.VehicleViolationsRepository;
import lombok.AllArgsConstructor;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;

/**
 * web-infrastructure
 *
 * @Author makejava
 * @Date 2026-03-05 11:33:29
 */
@Service
@AllArgsConstructor
public class VehicleViolationsGatewayImpl implements VehicleViolationsGateway {
    private final VehicleViolationsRepository vehicleViolationsRepository;

    @Override
    public Boolean add(VehicleViolationsE vehicleViolationsE) {
        VehicleViolationsDO d = new VehicleViolationsDO();
        BeanUtils.copyProperties(vehicleViolationsE, d);
        vehicleViolationsRepository.save(d);
        return true;
    }

    @Override
    public Boolean update(VehicleViolationsE vehicleViolationsE) {
        VehicleViolationsDO d = new VehicleViolationsDO();
        BeanUtils.copyProperties(vehicleViolationsE, d);
        vehicleViolationsRepository.updateById(d);
        return true;
    }

    @Override
    public Boolean deletedVehicleViolationsById(Long id) {
        return vehicleViolationsRepository.removeById(id);
    }

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

    @Override
    public List<VehicleViolationsE> listVehicleViolationByLicenceNo(String licenceNo) {
        List<VehicleViolationsDO> vehicleViolationsDOS = vehicleViolationsRepository.listVehicleViolationByLicenceNo(licenceNo);
        return vehicleViolationsDOS.stream().map(d -> {
            VehicleViolationsE e = new VehicleViolationsE();
            BeanUtils.copyProperties(d, e);
            return e;
        }).collect(Collectors.toList());
    }

    @Override
    public void updateVehicleViolationsStatusByLicenceNo(String licenceNo, int i) {
        UpdateWrapper<VehicleViolationsDO> updateWrapper = new UpdateWrapper<>();
        updateWrapper.set("violation_processing_status", i);
        updateWrapper.eq("licence_no", licenceNo);
        vehicleViolationsRepository.update(updateWrapper);
    }
}

