package com.zcloud.primeport.gatewayimpl;

import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.zcloud.primeport.domain.gateway.ClosedAreaFgsPersonAuthGateway;
import com.zcloud.primeport.domain.model.ClosedAreaFgsPersonAuthE;
import com.zcloud.primeport.persistence.dataobject.ClosedAreaFgsPersonAuthDO;
import com.zcloud.primeport.persistence.repository.ClosedAreaFgsPersonAuthRepository;
import com.zcloud.primeport.persistence.repository.ClosedAreaRepository;
import lombok.AllArgsConstructor;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

@Service
@AllArgsConstructor
public class ClosedAreaFgsPersonAuthGatewayImpl implements ClosedAreaFgsPersonAuthGateway {
    private final ClosedAreaFgsPersonAuthRepository closedAreaFgsPersonAuthRepository;

    @Override
    public void addOrUpdate(ClosedAreaFgsPersonAuthE closedAreaFgsPersonAuthE) {
        ClosedAreaFgsPersonAuthDO closedAreaFgsPersonAuthDO = new ClosedAreaFgsPersonAuthDO();
        BeanUtils.copyProperties(closedAreaFgsPersonAuthE, closedAreaFgsPersonAuthDO);
        closedAreaFgsPersonAuthRepository.saveOrUpdate(closedAreaFgsPersonAuthDO);
    }

    @Override
    public void removeByUserId(Long userId) {
        UpdateWrapper<ClosedAreaFgsPersonAuthDO> closedAreaFgsPersonAuthDOUpdateWrapper = new UpdateWrapper<>();
        closedAreaFgsPersonAuthDOUpdateWrapper.set("delete_enum","TRUE");
        closedAreaFgsPersonAuthDOUpdateWrapper.eq("user_id",userId);

        closedAreaFgsPersonAuthRepository.remove(closedAreaFgsPersonAuthDOUpdateWrapper);
    }
}
