/*
 * Copyright [2022] [https://www.xiaonuo.vip]
 *
 * Snowy采用APACHE LICENSE 2.0开源协议，您在使用过程中，需要注意以下几点：
 *
 * 1.请不要删除和修改根目录下的LICENSE文件。
 * 2.请不要删除和修改Snowy源码头部的版权声明。
 * 3.本项目代码可免费商业使用，商业使用请保留源码和相关描述文件的项目出处，作者声明等。
 * 4.分发源码时候，请注明软件出处 https://www.xiaonuo.vip
 * 5.不可二次分发开源参与同类竞品，如有想法可联系团队xiaonuobase@qq.com商议合作。
 * 6.若您的项目无法满足以上几点，需要更多功能代码，获取Snowy商业授权许可，请在官网购买授权，地址为 https://www.xiaonuo.vip
 */
package vip.xiaonuo.biz.modular.bizappointmentrecord.service.impl;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollStreamUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.PhoneUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.fhs.trans.service.impl.TransService;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletResponse;
import org.apache.commons.compress.utils.Lists;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import vip.xiaonuo.biz.modular.bizappointmentrecord.param.*;
import vip.xiaonuo.biz.modular.bizappointmenttime.entity.BizAppointmentTime;
import vip.xiaonuo.biz.modular.bizappointmenttime.service.BizAppointmentTimeService;
import vip.xiaonuo.biz.modular.bizconfig.entity.BizConfig;
import vip.xiaonuo.biz.modular.bizconfig.service.BizConfigService;
import vip.xiaonuo.biz.modular.bizorder.entity.BizOrder;
import vip.xiaonuo.biz.modular.bizorder.param.BizOrderExportResult;
import vip.xiaonuo.biz.modular.bizorder.service.BizOrderService;
import vip.xiaonuo.biz.modular.goods.entity.BizGoods;
import vip.xiaonuo.biz.modular.goods.service.BizGoodsService;
import vip.xiaonuo.biz.modular.record.entity.BizRecord;
import vip.xiaonuo.biz.modular.record.service.BizRecordService;
import vip.xiaonuo.biz.modular.utils.CommonExportUtil;
import vip.xiaonuo.common.enums.CommonSortOrderEnum;
import vip.xiaonuo.common.exception.CommonException;
import vip.xiaonuo.common.page.CommonPageRequest;
import vip.xiaonuo.biz.modular.bizappointmentrecord.entity.BizAppointmentRecord;
import vip.xiaonuo.biz.modular.bizappointmentrecord.mapper.BizAppointmentRecordMapper;
import vip.xiaonuo.biz.modular.bizappointmentrecord.service.BizAppointmentRecordService;

import java.io.IOException;
import java.util.List;
import java.util.regex.Pattern;

/**
 * 预约记录Service接口实现类
 *
 * @author fanzherong
 * @date  2025/03/24 14:47
 **/
@Service
public class BizAppointmentRecordServiceImpl extends ServiceImpl<BizAppointmentRecordMapper, BizAppointmentRecord> implements BizAppointmentRecordService {

    @Resource
    private BizConfigService bizConfigService;
    @Resource
    private BizAppointmentTimeService bizAppointmentTimeService;
    @Resource
    private TransService transService;
    @Resource
    private BizOrderService bizOrderService;
    @Resource
    private BizGoodsService bizGoodsService;
    @Resource
    private BizRecordService bizRecordService;

    @Override
    public Page<BizAppointmentRecord> page(BizAppointmentRecordPageParam bizAppointmentRecordPageParam) {
        QueryWrapper<BizAppointmentRecord> queryWrapper = getQueryWrapper(bizAppointmentRecordPageParam);
        return this.getBaseMapper().getPage(CommonPageRequest.defaultPage(), queryWrapper);
    }

    public QueryWrapper<BizAppointmentRecord> getQueryWrapper(BizAppointmentRecordPageParam bizAppointmentRecordPageParam){
        QueryWrapper<BizAppointmentRecord> queryWrapper = new QueryWrapper<BizAppointmentRecord>().checkSqlInjection();
        if(ObjectUtil.isNotEmpty(bizAppointmentRecordPageParam.getOrderName())){
            queryWrapper.like("bo.order_name",bizAppointmentRecordPageParam.getOrderName());
        }
        if(ObjectUtil.isNotEmpty(bizAppointmentRecordPageParam.getOrderNumber())){
            queryWrapper.like("bo.order_number",bizAppointmentRecordPageParam.getOrderNumber());
        }
        if(ObjectUtil.isNotEmpty(bizAppointmentRecordPageParam.getCustomerName())){
            queryWrapper.like("bc.customer_name",bizAppointmentRecordPageParam.getCustomerName());
        }
        if(ObjectUtil.isNotEmpty(bizAppointmentRecordPageParam.getDriverName())){
            queryWrapper.like("bar.driver_name",bizAppointmentRecordPageParam.getDriverName());
        }
        if(ObjectUtil.isNotEmpty(bizAppointmentRecordPageParam.getDriverMobile())){
            queryWrapper.like("bar.driver_mobile",bizAppointmentRecordPageParam.getDriverMobile());
        }
        if(ObjectUtil.isNotEmpty(bizAppointmentRecordPageParam.getGoodsName())){
            queryWrapper.like("bg.NAME",bizAppointmentRecordPageParam.getGoodsName());
        }
        if(ObjectUtil.isNotEmpty(bizAppointmentRecordPageParam.getLicenseNumber())){
            queryWrapper.like("bar.license_number",bizAppointmentRecordPageParam.getLicenseNumber());
        }
        if(ObjectUtil.isNotEmpty(bizAppointmentRecordPageParam.getStatus())){
            queryWrapper.eq("bar.status",bizAppointmentRecordPageParam.getStatus());
        }
        //车辆排队去除审核状态
        if(ObjectUtil.isNotEmpty(bizAppointmentRecordPageParam.getAppointmentFlag())){
            queryWrapper.notIn("bar.status","1","2");
        }
        queryWrapper.eq("bar.delete_flag","NOT_DELETE");
        queryWrapper.orderByDesc("bar.create_time");
        return queryWrapper;
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public void add(BizAppointmentRecordAddParam bizAppointmentRecordAddParam) {
        checkParam(bizAppointmentRecordAddParam);
        //获取流程配置判断预约是否需要审核
        BizConfig bizConfig = bizConfigService.getOne(new QueryWrapper<BizConfig>().lambda().last("limit 1"));
        BizAppointmentRecord bizAppointmentRecord = BeanUtil.toBean(bizAppointmentRecordAddParam, BizAppointmentRecord.class);
        if(ObjectUtil.isNotNull(bizConfig)){
            if(StringUtils.equals(bizConfig.getAuditSwitch(),"1")){
                //开启审核，设置待审核状态
                bizAppointmentRecord.setStatus("1");
            }else{
                //未开启审核，设置排队中状态
                bizAppointmentRecord.setStatus("3");
            }
        }
        this.save(bizAppointmentRecord);

        //更新时间段内已预约数
        BizAppointmentTime bizAppointmentTime = bizAppointmentTimeService.getById(bizAppointmentRecordAddParam.getTimeId());
        if(ObjectUtil.isNotNull(bizAppointmentTime)){
            bizAppointmentTime.setApplyNumberAlready(bizAppointmentTime.getApplyNumberAlready()+1);
            bizAppointmentTimeService.updateById(bizAppointmentTime);
        }
    }

    public void checkParam(BizAppointmentRecordAddParam bizAppointmentRecordAddParam){
        //校验车牌号
        if(ObjectUtil.isNotEmpty(bizAppointmentRecordAddParam.getLicenseNumber())){
            if(!isCarNumber(bizAppointmentRecordAddParam.getLicenseNumber().toUpperCase().trim())){
                throw new CommonException("车牌号：{}格式错误",bizAppointmentRecordAddParam.getLicenseNumber().toUpperCase().trim());
            }
            //校验车牌号是否添加过预约，排除11：已签收、 13:销售已审核  、 14：已取消
            long count = this.count(new QueryWrapper<BizAppointmentRecord>().lambda().
                    eq(BizAppointmentRecord::getLicenseNumber,bizAppointmentRecordAddParam.getLicenseNumber().toUpperCase().trim()).
                    notIn(BizAppointmentRecord::getStatus, "11", "13", "14"));
            if(count>0){
                throw new CommonException("车牌号：{}已经添加过预约！",bizAppointmentRecordAddParam.getLicenseNumber().toUpperCase().trim());
            }
        }
        //校验手机号
        if(ObjectUtil.isNotEmpty(bizAppointmentRecordAddParam.getDriverMobile())){
            if(!PhoneUtil.isMobile(bizAppointmentRecordAddParam.getDriverMobile())) {
                throw new CommonException("手机号码：{}格式错误", bizAppointmentRecordAddParam.getDriverMobile());
            }
        }
        if(ObjectUtil.isNotEmpty(bizAppointmentRecordAddParam.getTimeId())){
            //校验预约时间段是否预约满
            //查询预约时间段内的预约记录,10：已出场   11：已签收   12:自动审核  13:销售已审核   14：已取消这些状态都占用预约名额
            long count = this.count(new QueryWrapper<BizAppointmentRecord>().lambda().
                    eq(BizAppointmentRecord::getTimeId, bizAppointmentRecordAddParam.getTimeId()).
                    notIn(BizAppointmentRecord::getStatus, "10", "11", "12", "13", "14"));
            //查询预约时间段内可预约次数
            BizAppointmentTime bizAppointmentTime = bizAppointmentTimeService.getById(bizAppointmentRecordAddParam.getTimeId());
            if(count>=bizAppointmentTime.getApplyNumber()){
                throw new CommonException("该时间段已经预约满！");
            }
        }

    }

    public void checkParam(BizAppointmentRecordEditParam bizAppointmentRecordEditParam,BizAppointmentRecord bizAppointmentRecord){
        //校验车牌号
        if(ObjectUtil.isNotEmpty(bizAppointmentRecordEditParam.getLicenseNumber())){
            if(!StringUtils.equals(bizAppointmentRecord.getLicenseNumber(),bizAppointmentRecordEditParam.getLicenseNumber())){
                //车牌号修改过
                if(!isCarNumber(bizAppointmentRecordEditParam.getLicenseNumber().toUpperCase().trim())){
                    throw new CommonException("车牌号：{}格式错误",bizAppointmentRecordEditParam.getLicenseNumber().toUpperCase().trim());
                }
                //校验车牌号是否添加过预约，排除11：已签收、 13:销售已审核  、 14：已取消
                long count = this.count(new QueryWrapper<BizAppointmentRecord>().lambda().
                        eq(BizAppointmentRecord::getLicenseNumber,bizAppointmentRecordEditParam.getLicenseNumber().toUpperCase().trim()).
                        notIn(BizAppointmentRecord::getStatus, "11", "13", "14"));
                if(count>0){
                    throw new CommonException("车牌号：{}已经添加过预约！",bizAppointmentRecordEditParam.getLicenseNumber().toUpperCase().trim());
                }
            }
        }
        //校验手机号
        if(ObjectUtil.isNotEmpty(bizAppointmentRecordEditParam.getDriverMobile())){
            if(!PhoneUtil.isMobile(bizAppointmentRecordEditParam.getDriverMobile())) {
                throw new CommonException("手机号码：{}格式错误", bizAppointmentRecordEditParam.getDriverMobile());
            }
        }
        if(ObjectUtil.isNotEmpty(bizAppointmentRecordEditParam.getTimeId())){
            if(!StringUtils.equals(bizAppointmentRecord.getTimeId(),bizAppointmentRecordEditParam.getTimeId())){
                //校验预约时间段是否预约满
                //查询预约时间段内的预约记录,10：已出场   11：已签收   12:自动审核  13:销售已审核   14：已取消这些状态都占用预约名额
                long count = this.count(new QueryWrapper<BizAppointmentRecord>().lambda().
                        eq(BizAppointmentRecord::getTimeId, bizAppointmentRecordEditParam.getTimeId()).
                        notIn(BizAppointmentRecord::getStatus, "10", "11", "12", "13", "14"));
                //查询预约时间段内可预约次数
                BizAppointmentTime bizAppointmentTime = bizAppointmentTimeService.getById(bizAppointmentRecordEditParam.getTimeId());
                if(count>=bizAppointmentTime.getApplyNumber()){
                    throw new CommonException("该时间段已经预约满！");
                }
            }

        }

    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public void edit(BizAppointmentRecordEditParam bizAppointmentRecordEditParam) {
        BizAppointmentRecord bizAppointmentRecord = this.queryEntity(bizAppointmentRecordEditParam.getId());
        checkParam(bizAppointmentRecordEditParam,bizAppointmentRecord);
        if(!StringUtils.equals(bizAppointmentRecord.getTimeId(),bizAppointmentRecordEditParam.getTimeId())){
            //调整了预约时段，释放之前预约时段的预约次数
            BizAppointmentTime bizAppointmentTime = bizAppointmentTimeService.getById(bizAppointmentRecord.getTimeId());
            bizAppointmentTime.setApplyNumberAlready(bizAppointmentTime.getApplyNumberAlready()-1);
            bizAppointmentTimeService.updateById(bizAppointmentTime);

            //新的预约时段，增加已约次数
            BizAppointmentTime time = bizAppointmentTimeService.getById(bizAppointmentRecordEditParam.getTimeId());
            time.setApplyNumberAlready(time.getApplyNumberAlready()+1);
            bizAppointmentTimeService.updateById(time);
        }
        BeanUtil.copyProperties(bizAppointmentRecordEditParam, bizAppointmentRecord);
        if(StringUtils.equals(bizAppointmentRecord.getStatus(),"2")){
            //如果当前状态是审核不通过的状态，修改后重新提交审核
            bizAppointmentRecord.setStatus("1");
        }
        this.updateById(bizAppointmentRecord);
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public void delete(List<BizAppointmentRecordIdParam> bizAppointmentRecordIdParamList) {
        //释放预约数
        for(BizAppointmentRecordIdParam bizAppointmentRecordIdParam : bizAppointmentRecordIdParamList){
            BizAppointmentRecord bizAppointmentRecord = this.queryEntity(bizAppointmentRecordIdParam.getId());
            BizAppointmentTime bizAppointmentTime = bizAppointmentTimeService.getById(bizAppointmentRecord.getTimeId());
            if(ObjectUtil.isNotNull(bizAppointmentTime)){
                bizAppointmentTime.setApplyNumberAlready(bizAppointmentTime.getApplyNumberAlready()-1);
                bizAppointmentTimeService.updateById(bizAppointmentTime);
            }
        }
        // 执行删除
        this.removeByIds(CollStreamUtil.toList(bizAppointmentRecordIdParamList, BizAppointmentRecordIdParam::getId));
    }

    @Override
    public BizAppointmentRecord detail(BizAppointmentRecordIdParam bizAppointmentRecordIdParam) {
        return this.queryEntity(bizAppointmentRecordIdParam.getId());
    }

    @Override
    public BizAppointmentRecord queryEntity(String id) {
        BizAppointmentRecord bizAppointmentRecord = this.getById(id);
        if(ObjectUtil.isEmpty(bizAppointmentRecord)) {
            throw new CommonException("预约记录不存在，id值为：{}", id);
        }
        return bizAppointmentRecord;
    }

    @Override
    public void auditRecord(BizAppointmentRecordEditParam bizAppointmentRecordEditParam) {
        BizAppointmentRecord bizAppointmentRecord = this.queryEntity(bizAppointmentRecordEditParam.getId());
        if(ObjectUtil.isNotEmpty(bizAppointmentRecordEditParam.getAuditFlag())){
            if(StringUtils.equals(bizAppointmentRecordEditParam.getAuditFlag(),"true")){
                bizAppointmentRecord.setStatus("2");
            }else{
                bizAppointmentRecord.setStatus("3");
            }
            bizAppointmentRecord.setAppointmentReason(bizAppointmentRecordEditParam.getAppointmentReason());
            this.updateById(bizAppointmentRecord);
        }
    }

    @Override
    public void exportRecord(BizAppointmentRecordPageParam bizAppointmentRecordPageParam, HttpServletResponse response) throws IOException {
        QueryWrapper<BizAppointmentRecord> queryWrapper = getQueryWrapper(bizAppointmentRecordPageParam);
        List<BizAppointmentRecord> recordList = this.getBaseMapper().getPage(queryWrapper);
        String fileName = "预约报表.xlsx";
        List<BizAppointmentExportResult> list = Lists.newArrayList();
        transService.transBatch(recordList);
        for(BizAppointmentRecord bizAppointmentRecord : recordList){
            BizAppointmentExportResult bizAppointmentExportResult = new BizAppointmentExportResult();
            BeanUtil.copyProperties(bizAppointmentRecord, bizAppointmentExportResult);
            bizAppointmentExportResult.setStatusName((String) bizAppointmentRecord.getTransMap().get("statusName"));
            bizAppointmentExportResult.setTimeInfo(bizAppointmentRecord.getBeginTime()+"~"+bizAppointmentRecord.getEndTime());
            list.add(bizAppointmentExportResult);
        }
        CommonExportUtil.export(fileName, BizAppointmentExportResult.class,list,response,"预约报表");
    }

    @Override
    public BizAppointmentRecord checkAppointmentRecord(BizAppointmentRecordPageParam bizAppointmentRecordPageParam) {
        //根据车牌号和状态查询
        BizAppointmentRecord bizAppointmentRecord = this.getOne(new QueryWrapper<BizAppointmentRecord>().lambda().
                eq(BizAppointmentRecord::getLicenseNumber, bizAppointmentRecordPageParam.getLicenseNumber()).
                eq(BizAppointmentRecord::getStatus, bizAppointmentRecordPageParam.getStatus()).
                last("limit 1"));
        if(StringUtils.equals(bizAppointmentRecordPageParam.getStatus(),"4")){
            //待入场,如果为空，没有待入场的记录，不可进门禁
            if(ObjectUtil.isNull(bizAppointmentRecord)){
                bizAppointmentRecord = new BizAppointmentRecord();
                bizAppointmentRecord.setIsFlag("4");
            }else{
                bizAppointmentRecord = setBizAppointmentRecord(bizAppointmentRecord);
            }
        }else if(StringUtils.equals(bizAppointmentRecordPageParam.getStatus(),"5")){
            //已入场，如果为空，没有已入场的记录，不可一次过磅
            if(ObjectUtil.isNull(bizAppointmentRecord)){
                bizAppointmentRecord = new BizAppointmentRecord();
                bizAppointmentRecord.setIsFlag("5");
            }else{
                bizAppointmentRecord = setBizAppointmentRecord(bizAppointmentRecord);
            }
        }else if(StringUtils.equals(bizAppointmentRecordPageParam.getStatus(),"7")){
            //完成装货，如果为空，没有完成装货的记录，不可二次过磅
            if(ObjectUtil.isNull(bizAppointmentRecord)){
                bizAppointmentRecord = new BizAppointmentRecord();
                bizAppointmentRecord.setIsFlag("7");
            }else{
                bizAppointmentRecord = setBizAppointmentRecord(bizAppointmentRecord);
            }
        }else if(StringUtils.equals(bizAppointmentRecordPageParam.getStatus(),"9")){
            //待出场，如果为空，没有待出场的记录，不可出门禁
            if(ObjectUtil.isNull(bizAppointmentRecord)){
                bizAppointmentRecord = new BizAppointmentRecord();
                bizAppointmentRecord.setIsFlag("9");
            }else{
                bizAppointmentRecord = setBizAppointmentRecord(bizAppointmentRecord);
            }
        }
        return bizAppointmentRecord;
    }

    @Transactional
    @Override
    public void cancelAppointmentRecord(BizAppointmentRecordIdParam bizAppointmentRecordIdParam) {
        BizAppointmentRecord bizAppointmentRecord = this.queryEntity(bizAppointmentRecordIdParam.getId());
        //设置已取消
        bizAppointmentRecord.setStatus("14");
        this.updateById(bizAppointmentRecord);

        //释放预约数
        BizAppointmentTime bizAppointmentTime = bizAppointmentTimeService.getById(bizAppointmentRecord.getTimeId());
        if(ObjectUtil.isNotNull(bizAppointmentTime)){
            bizAppointmentTime.setApplyNumberAlready(bizAppointmentTime.getApplyNumberAlready()-1);
            bizAppointmentTimeService.updateById(bizAppointmentTime);
        }
    }

    @Transactional
    @Override
    public void adjustOrder(BizAppointmentRecordEditParam bizAppointmentRecordEditParam) {
        BizAppointmentRecord bizAppointmentRecord = this.queryEntity(bizAppointmentRecordEditParam.getId());
        if(!StringUtils.equals(bizAppointmentRecord.getOrderId(),bizAppointmentRecordEditParam.getOrderId())){
            //调整过订单
            if(StringUtils.equals(bizAppointmentRecord.getStatus(),"8") || StringUtils.equals(bizAppointmentRecord.getStatus(),"9")){
                //查询过磅记录重量
                BizRecord bizRecord = bizRecordService.getOne(new QueryWrapper<BizRecord>().lambda().
                        eq(BizRecord::getAppointmentId, bizAppointmentRecord.getId()).
                        last("limit 1"));
                //当前状态已完成二次过磅，重量已经添加到订单中，要扣去添加的重量
                BizOrder bizOrder = bizOrderService.getById(bizAppointmentRecord.getOrderId());
                if(ObjectUtil.isNotNull(bizOrder)){
                    if(ObjectUtil.isNotNull(bizRecord)){
                        bizOrder.setNetWeight(bizOrder.getNetWeight().subtract(bizRecord.getNetWeight()));
                    }
                }

                //修改后的订单加上净重
                BizOrder order = bizOrderService.getById(bizAppointmentRecordEditParam.getOrderId());
                if(ObjectUtil.isNotNull(order)){
                    if(ObjectUtil.isNotNull(bizRecord)){
                        order.setNetWeight(order.getNetWeight().add(bizRecord.getNetWeight()));
                    }
                }
            }else{
                bizAppointmentRecord.setOrderId(bizAppointmentRecordEditParam.getOrderId());
            }
            this.updateById(bizAppointmentRecord);
        }
    }

    public BizAppointmentRecord setBizAppointmentRecord(BizAppointmentRecord bizAppointmentRecord){
        bizAppointmentRecord.setIsFlag("1");
        if(ObjectUtil.isNotEmpty(bizAppointmentRecord.getOrderId())){
            BizOrder bizOrder = bizOrderService.getById(bizAppointmentRecord.getOrderId());
            if(ObjectUtil.isNotNull(bizOrder)){
                if(ObjectUtil.isNotEmpty(bizOrder.getGoodId())){
                    BizGoods bizGoods = bizGoodsService.getById(bizOrder.getGoodId());
                    if(ObjectUtil.isNotNull(bizGoods)){
                        bizAppointmentRecord.setGoodsName(bizGoods.getGoodsName());
                        bizAppointmentRecord.setGoodsModel(bizGoods.getGoodsModel());
                    }
                }
            }
        }
        return bizAppointmentRecord;
    }

    /**
     * 车牌号校验
     * @param carNumber
     * @return
     */
    public boolean isCarNumber(String carNumber){
        String carNumberPattern = "([京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼]{1}(([A-HJ-Z]{1}[A-HJ-NP-Z0-9]{5})|([A-HJ-Z]{1}(([DF]{1}[A-HJ-NP-Z0-9]{1}[0-9]{4})|([0-9]{5}[DF]{1})))|([A-HJ-Z]{1}[A-D0-9]{1}[0-9]{3}警)))|([0-9]{6}使)|((([沪粤川云桂鄂陕蒙藏黑辽渝]{1}A)|鲁B|闽D|蒙E|蒙H)[0-9]{4}领)|(WJ[京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼·•]{1}[0-9]{4}[TDSHBXJ0-9]{1})|([VKHBSLJNGCE]{1}[A-DJ-PR-TVY]{1}[0-9]{5})";
        return Pattern.matches(carNumberPattern, carNumber);
    }
}
