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.IDCardVO;
import org.springblade.thirdparty.ocr.util.ConvertUtil;

import java.util.function.BiConsumer;

/**
 *  身份证转换
 * @author bfhuange
 * @date 2024/11/6
 */
@Slf4j
@AllArgsConstructor
@Getter
public enum IDCardConvert {
    /**
     *  姓名
     */
    NAME(OCRImageType.ID_CARD_MAIN, OCRKey.KeyInfo.NAME, IDCardVO::setName),
    /**
     *  身份证号
     */
    ID_NO(OCRImageType.ID_CARD_MAIN, OCRKey.KeyInfo.ID_NO, IDCardVO::setIdNo),
    /**
     *  性别
     */
    GENDER(OCRImageType.ID_CARD_MAIN, OCRKey.KeyInfo.ID_CARD_MAIN_GENDER, IDCardVO::setGender),
    /**
     *  民族
     */
    NATION(OCRImageType.ID_CARD_MAIN, OCRKey.KeyInfo.ID_CARD_MAIN_ETHNIC_GROUP, IDCardVO::setNation),
    /**
     *  出生年月日
     */
    BIRTHDAY(OCRImageType.ID_CARD_MAIN, OCRKey.KeyInfo.DATE, (idCard, dateString) ->
            ConvertUtil.convertDate(dateString).accept(idCard::setBirthday)),
    /**
     *  有效期止
     */
    VALID_DATE_END(OCRImageType.ID_CARD_SIDE, OCRKey.KeyInfo.DATE_VALID, (idCard, dateString) -> ConvertUtil.extractEndDate(dateString)
            .accept(idCard::setValidDateEnd)),
    ;
    /**
     *  图像类型列表
     */
    private final OCRImageType imageType;
    /**
     *  字段配置
     */
    private final OCRKey.KeyInfo keyInfo;
    /**
     *  setter方法
     */
    private final BiConsumer<IDCardVO, String> setter;

}
