package org.springblade.thirdparty.ocr.convert;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
import org.springblade.thirdparty.ocr.constant.OCRImageType;
import org.springblade.thirdparty.ocr.constant.OCRKey;
import org.springblade.thirdparty.ocr.pojo.vo.TransportCertificateVO;

import java.util.Collections;
import java.util.List;
import java.util.function.BiConsumer;

import static org.springblade.thirdparty.ocr.util.ConvertUtil.*;

/**
 *  车辆运输凭证转换
 * @author bfhuange
 * @date 2024/11/6
 */
@Slf4j
@AllArgsConstructor
@Getter
public enum TransportCertificateConvert {
    /**
     *  车头车牌号
     */
    CAR_FRONT_PLATE_NO(OCRImageType.CAR_FRONT, OCRKey.KeyInfo.PLATE_NO, TransportCertificateVO::setCarFrontPlateNo),
    /**
     *  车尾车牌号
     */
    CAR_BACK_PLATE_NO(OCRImageType.CAR_BACK, OCRKey.KeyInfo.PLATE_NO, TransportCertificateVO::setCarBackPlateNo),
    /**
     *  行驶证上的车牌号
     */
    DRIVING_PLATE_NO(List.of(OCRImageType.VEHICLE_LICENSE_MAIN, OCRImageType.VEHICLE_LICENSE_MAIN_OTHERS), OCRKey.KeyInfo.PLATE_NO, (transportCertificate, plateNo) -> {
        transportCertificate.setDrivingPlateNo(plateNo);
        transportCertificate.setVehicleLicensePlateNo(plateNo);
    }),
    /**
     *  行驶证车辆类型
     */
    VEHICLE_LICENSE_VEHICLE_TYPE(List.of(OCRImageType.VEHICLE_LICENSE_MAIN, OCRImageType.VEHICLE_LICENSE_MAIN_OTHERS), OCRKey.KeyInfo.VEHICLE_TYPE, TransportCertificateVO::setVehicleLicenseVehicleType),
    /**
     *  行驶证所有人
     */
    VEHICLE_LICENSE_OWNER_NAME(List.of(OCRImageType.VEHICLE_LICENSE_MAIN, OCRImageType.VEHICLE_LICENSE_MAIN_OTHERS), OCRKey.KeyInfo.NAME, TransportCertificateVO::setVehicleLicenseOwnerName),
    /**
     *  行驶证使用性质
     */
    VEHICLE_LICENSE_USE_CHARACTER(List.of(OCRImageType.VEHICLE_LICENSE_MAIN, OCRImageType.VEHICLE_LICENSE_MAIN_OTHERS), OCRKey.KeyInfo.USE_CHARACTER, TransportCertificateVO::setVehicleLicenseUseCharacter),
    /**
     *  行驶证品牌型号
     */
    VEHICLE_LICENSE_MODEL(List.of(OCRImageType.VEHICLE_LICENSE_MAIN, OCRImageType.VEHICLE_LICENSE_MAIN_OTHERS), OCRKey.KeyInfo.MODEL, TransportCertificateVO::setVehicleLicenseModel),
    /**
     *  行驶证车辆识别代号
     */
    VEHICLE_LICENSE_VIN(List.of(OCRImageType.VEHICLE_LICENSE_MAIN, OCRImageType.VEHICLE_LICENSE_MAIN_OTHERS), OCRKey.KeyInfo.VIN, TransportCertificateVO::setVehicleLicenseVin),
    /**
     *  行驶证发动机号码
     */
    VEHICLE_LICENSE_ENGINE_NO(List.of(OCRImageType.VEHICLE_LICENSE_MAIN, OCRImageType.VEHICLE_LICENSE_MAIN_OTHERS), OCRKey.KeyInfo.ENGINE_NO, TransportCertificateVO::setVehicleLicenseEngineNo),
    /**
     *  行驶证注册日期
     */
    VEHICLE_LICENSE_REGISTER_DATE(List.of(OCRImageType.VEHICLE_LICENSE_MAIN, OCRImageType.VEHICLE_LICENSE_MAIN_OTHERS), OCRKey.KeyInfo.DATE_REGISTER, (transportCertificate, dateString) -> convertDate(dateString)
            .accept(transportCertificate::setVehicleLicenseRegisterDate)),
    /**
     *  行驶证发证日期
     */
    VEHICLE_LICENSE_ISSUE_DATE(List.of(OCRImageType.VEHICLE_LICENSE_MAIN, OCRImageType.VEHICLE_LICENSE_MAIN_OTHERS), OCRKey.KeyInfo.DATE_ISSUE, (transportCertificate, dateString) -> convertDate(dateString)
            .accept(transportCertificate::setVehicleLicenseIssueDate)),
    /**
     *  行驶证住址
     */
    VEHICLE_LICENSE_ADDRESS(List.of(OCRImageType.VEHICLE_LICENSE_MAIN, OCRImageType.VEHICLE_LICENSE_MAIN_OTHERS), OCRKey.KeyInfo.ADDRESS, TransportCertificateVO::setVehicleLicenseAddress),
    /**
     *  行驶证档案编号
     */
    VEHICLE_LICENSE_FILE_NO(OCRImageType.VEHICLE_LICENSE_SIDE, OCRKey.KeyInfo.FILE_NO, TransportCertificateVO::setVehicleLicenseFileNo),
    /**
     *  行驶证检验有效期
     */
    VEHICLE_LICENSE_INSPECTION_VALID_DATE(OCRImageType.VEHICLE_LICENSE_SIDE, OCRKey.KeyInfo.DATE_VALID_INSPECTION, (transportCertificate, dateString) -> extractEndDate(dateString)
            .accept(transportCertificate::setVehicleLicenseInspectionValidDate)),
    /**
     *  驾驶证有效期限(终⽌时间)
     */
    DRIVER_LICENSE_VALID_DATE_END(List.of(OCRImageType.DRIVER_LICENSE_MAIN, OCRImageType.DRIVER_LICENSE_ELEC), OCRKey.KeyInfo.DATE_VALID, (transportCertificate, dateString) -> convertDateValid(dateString)
            .accept(transportCertificate::setDriverLicenseValidDateEnd)),
    /**
     *  驾驶证姓名
     */
    DRIVER_LICENSE_NAME(List.of(OCRImageType.DRIVER_LICENSE_MAIN, OCRImageType.DRIVER_LICENSE_ELEC), OCRKey.KeyInfo.NAME, TransportCertificateVO::setDriverLicenseName),
    /**
     *  驾驶证证号
     */
    DRIVER_LICENSE_ID_NO(List.of(OCRImageType.DRIVER_LICENSE_MAIN, OCRImageType.DRIVER_LICENSE_ELEC), OCRKey.KeyInfo.ID_NO, TransportCertificateVO::setDriverLicenseIdNo),
    /**
     *  驾驶证档案编号
     */
    DRIVER_LICENSE_FILE_NO(OCRImageType.DRIVER_LICENSE_SIDE, OCRKey.KeyInfo.FILE_NO, TransportCertificateVO::setDriverLicenseFileNo),
    /**
     *  准驾车型
     */
    DRIVER_LICENSE_TYPE(List.of(OCRImageType.DRIVER_LICENSE_MAIN, OCRImageType.DRIVER_LICENSE_ELEC), OCRKey.KeyInfo.CLASS, TransportCertificateVO::setDriverLicenseType),
    /**
     *  驾驶证有效期限(起始时间)
     */
    DRIVER_LICENSE_VALID_DATE_START(List.of(OCRImageType.DRIVER_LICENSE_MAIN, OCRImageType.DRIVER_LICENSE_ELEC), OCRKey.KeyInfo.DATE_VALID, (transportCertificate, dateString) -> extractStartDate(dateString)
            .accept(transportCertificate::setDriverLicenseValidDateStart)),
    /**
     *  驾驶证有效期限(起始时间)
     */
    DRIVER_LICENSE_VALID_DATE_START_VALUE(List.of(OCRImageType.DRIVER_LICENSE_MAIN, OCRImageType.DRIVER_LICENSE_ELEC), OCRKey.KeyInfo.DATE_VALID_START, (transportCertificate, dateString) -> convertDate(dateString)
            .accept(transportCertificate::setDriverLicenseValidDateStart)),
    /**
     *  驾驶证有效期限(终⽌时间)
     */
    DRIVER_LICENSE_VALID_DATE_END_VALUE(List.of(OCRImageType.DRIVER_LICENSE_MAIN, OCRImageType.DRIVER_LICENSE_ELEC), OCRKey.KeyInfo.DATE_VALID_END, (transportCertificate, dateString) -> convertDate(dateString)
            .accept(transportCertificate::setDriverLicenseValidDateEnd)),
    /**
     *  磅单车牌号
     */
    POUND_PLATE_NO(Collections.emptyList(), OCRKey.KeyInfo.PLATE_NO, TransportCertificateVO::setPoundPlateNo),
    /**
     *  磅单供货日期
     */
    POUND_DATE(Collections.emptyList(), OCRKey.KeyInfo.DATE, (transportCertificate, dateString) -> convertDate(dateString)
            .accept(transportCertificate::setSupplyMaterialDate)),
    /**
     *  单位
     */
    UNIT_MEASURE(Collections.emptyList(), OCRKey.KeyInfo.UNIT_MEASURE, TransportCertificateVO::setUnitMeasure),
    /**
     *  货品名称
     */
    NAME_GOODS(Collections.emptyList(), OCRKey.KeyInfo.NAME_GOODS, TransportCertificateVO::setProductName),
    /**
     *  物料规格
     */
    NAME_MATERIAL(Collections.emptyList(), OCRKey.KeyInfo.NAME_MATERIAL, TransportCertificateVO::setSpecificationMaterial),
    /**
     *  ⽑重
     */
    GROSS_WEIGHT(Collections.emptyList(), OCRKey.KeyInfo.WEIGHT_GROSS, (transportCertificate, string) -> convertWeightBigDecimal(string)
            .accept(transportCertificate::setGrossWeight)),
    /**
     *  ⽪重
     */
    TARE_WEIGHT(Collections.emptyList(), OCRKey.KeyInfo.WEIGHT_TARE, (transportCertificate, string) -> convertWeightBigDecimal(string)
            .accept(transportCertificate::setSkinWeight)),
    /**
     *  净重
     */
    NET_WEIGHT(Collections.emptyList(), OCRKey.KeyInfo.WEIGHT_NET, (transportCertificate, string) -> convertWeightBigDecimal(string)
            .accept(transportCertificate::setNetWeight)),
    /**
     *  扣重
     */
    DEDUCT_WEIGHT(Collections.emptyList(), OCRKey.KeyInfo.WEIGHT_DEDUCT, (transportCertificate, string) -> convertWeightBigDecimal(string)
            .accept(transportCertificate::setMiscellaneousWeight)),
    /**
     *  实际净重
     */
    RECEIVED_WEIGHT(Collections.emptyList(), OCRKey.KeyInfo.WEIGHT_RECEIVED, (transportCertificate, string) -> convertWeightBigDecimal(string)
            .accept(transportCertificate::setRealityWeight)),

    ;
    /**
     *  图像类型列表
     */
    private final List<OCRImageType> imageTypes;
    /**
     *  字段配置
     */
    private final OCRKey.KeyInfo keyInfo;
    /**
     *  setter方法
     */
    private final BiConsumer<TransportCertificateVO, String> setter;

    TransportCertificateConvert(OCRImageType imageType, OCRKey.KeyInfo keyInfo, BiConsumer<TransportCertificateVO, String> setter) {
        this.imageTypes = List.of(imageType);
        this.keyInfo = keyInfo;
        this.setter = setter;
    }

}
