package com.cico.nest.lcdp.boot.core.qxsd.application.service.impl;

import com.cico.nest.lcdp.boot.core.qxsd.adapter.web.vo.tunnelHoleLine.*;
import com.cico.nest.lcdp.boot.core.qxsd.application.service.TunnelHoleMarkerlineService;
import com.cico.nest.lcdp.boot.core.qxsd.infrastructure.gatewayimpl.database.TunnelHoleMarkerlineMapper;
import com.cico.nest.lcdp.boot.core.qxsd.infrastructure.gatewayimpl.database.dataobject.TunnelHoleMarkerlineDO;
import org.springframework.stereotype.Service;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.transaction.annotation.Transactional;
import java.util.*;
import com.cico.nest.lcdp.framework.common.pojo.PageResult;
import com.cico.nest.lcdp.framework.common.pojo.PageParam;
import com.cico.nest.lcdp.framework.common.util.object.BeanUtils;
import static com.cico.nest.lcdp.framework.common.exception.enums.GlobalErrorCodeConstants.INTERNAL_SERVER_ERROR;
import static com.cico.nest.lcdp.framework.common.exception.util.ServiceExceptionUtil.exception;

/**
 * 隧道上下行洞车道标志线 Service 实现类
 *
 * @author 管理员
 */
@Service
@Validated
public class TunnelHoleMarkerlineServiceImpl implements TunnelHoleMarkerlineService {

    @Resource
    private TunnelHoleMarkerlineMapper tunnelHoleMarkerlineMapper;

    @Override
    public String createTunnelHoleMarkerline(TunnelHoleMarkerlineSaveReqVO createReqVO) {
        // 插入
        TunnelHoleMarkerlineDO tunnelHoleMarkerline = BeanUtils.toBean(createReqVO, TunnelHoleMarkerlineDO.class);
        tunnelHoleMarkerlineMapper.insert(tunnelHoleMarkerline);
        // 返回
        return tunnelHoleMarkerline.getId();
    }

    @Override
    public void updateTunnelHoleMarkerline(TunnelHoleMarkerlineSaveReqVO updateReqVO) {
        // 校验存在
        validateTunnelHoleMarkerlineExists(updateReqVO.getId());
        // 更新
        TunnelHoleMarkerlineDO updateObj = BeanUtils.toBean(updateReqVO, TunnelHoleMarkerlineDO.class);
        tunnelHoleMarkerlineMapper.updateById(updateObj);
    }

    @Override
    public void deleteTunnelHoleMarkerline(String id) {
        // 校验存在
        validateTunnelHoleMarkerlineExists(id);
        // 删除
        tunnelHoleMarkerlineMapper.deleteById(id);
    }

    private void validateTunnelHoleMarkerlineExists(String id) {
        if (tunnelHoleMarkerlineMapper.selectById(id) == null) {
            throw exception(INTERNAL_SERVER_ERROR.getCode(), "隧道洞标志线不存在");
        }
    }

    @Override
    public TunnelHoleMarkerlineDO getTunnelHoleMarkerline(String id) {
        return tunnelHoleMarkerlineMapper.selectById(id);
    }

    @Override
    public PageResult<TunnelHoleMarkerlineDO> getTunnelHoleMarkerlinePage(TunnelHoleMarkerlinePageReqVO pageReqVO) {
        return tunnelHoleMarkerlineMapper.selectPage(pageReqVO);
    }

}
