package com.heyu.api.baidu.handle.certificate;


import com.alibaba.fastjson.JSON;
import com.google.common.collect.Maps;
import com.heyu.api.data.annotation.CustomPath;
import com.heyu.api.data.utils.StringUtils;
import com.heyu.api.baidu.BaiduBaseHandle;
import com.heyu.api.baidu.request.certificate.BBouseholdRegisterRequest;
import com.heyu.api.baidu.response.certificate.BBouseholdRegisterResp;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.util.Map;

/**
 * https://console.bce.baidu.com/support/?_=1740219852952&timestamp=1740309163756#/api?product=AI&project=%E6%96%87%E5%AD%97%E8%AF%86%E5%88%AB&parent=%E5%8D%A1%E8%AF%81OCR&api=rest%2F2.0%2Focr%2Fv1%2Fhousehold_register&method=post
 * <p>
 * <p>
 * 户口本识别
 */
@Component
@Slf4j
@CustomPath("bouseholdRegister")
public class BBouseholdRegisterHandle extends BaiduBaseHandle<BBouseholdRegisterRequest, BBouseholdRegisterResp> {


    public final static Map<String, String> suportPage = Maps.newHashMap();

    static {
        suportPage.put("subpage", "默认值，常住人口登记卡（成员页）");
        suportPage.put("homepage", "户主页");
    }

    @Override
    public String getUri() {
        return "/rest/2.0/ocr/v1/household_register";
    }

    @Override
    public String check(BBouseholdRegisterRequest bBouseholdRegisterRequest) {
        if (suportPage.containsKey(bBouseholdRegisterRequest.getHouseholdRegisterSide())) {
            return "householdRegisterSide必须为" + JSON.toJSONString(suportPage) + "，subpage：默认值，常住人口登记卡（成员页）,homepage：户主页";
        }
        return checkImageUri(bBouseholdRegisterRequest);
    }

    @Override
    public String getContent(BBouseholdRegisterRequest bBouseholdRegisterRequest) {
        StringBuffer sb = getImageContent(bBouseholdRegisterRequest);
        if (StringUtils.isNotBlank(bBouseholdRegisterRequest.getHouseholdRegisterSide())) {
            sb.append("&household_register_side=").append(bBouseholdRegisterRequest.getHouseholdRegisterSide());
        }
        return sb.toString();
    }
}
