package review_service

import (
	"github.com/huaweicloud/huaweicloud-sdk-go-v3/services/ocr/v1/model"
	"youngee_b_api/app/dao"
	"youngee_b_api/app/entity"
	"youngee_b_api/app/vo"
)

func (c *Config) CheckBusinessLicense(param *vo.IdentifyParam) (map[string]string, error) {
	request := &model.RecognizeBusinessLicenseRequest{}
	request.Body = &model.BusinessLicenseRequestBody{
		Url: &param.BusinessLicenseUrl,
	}
	response, err := c.OcrClient.RecognizeBusinessLicense(request)
	if err != nil {
		return nil, err
	}
	result := response.Result
	registrationNumber := result.RegistrationNumber
	companyName := result.Name
	address := result.Address
	bodyType := result.Type // 公司/企业类型/主体类型/类型
	err1 := dao.EnterpriseDao{}.UpdateEnterprise(entity.Enterprise{
		EnterpriseID: param.EnterpriseId,
		BusinessName: *companyName,
		TaxNumber:    *registrationNumber,
		Address:      *address,
		AuthStatus:   1,
	})
	if err1 != nil {
		return nil, err1
	}
	resultMap := make(map[string]string)
	resultMap["registrationNumber"] = *registrationNumber // 企业税号
	resultMap["companyName"] = *companyName
	resultMap["address"] = *address
	resultMap["type"] = *bodyType

	return resultMap, nil
}
