package aduserdb

//
//import (
//	"errors"
//	"go-admin/app/admin/models"
//	"go-admin/app/admin/service/dto"
//
//	"go.uber.org/zap"
//	"gorm.io/gorm"
//
//	log "github.com/go-admin-team/go-admin-core/logger"
//)
//
//// AddJunior 初级认证
//func AddJunior(orm *gorm.DB, ident models.AdIdentification) error {
//	err := orm.Model(ident).Create(ident).Error
//	// err := dbhelper.MasterPgdb.InsertTx("ad_identification", &ident, tx)
//	if err != nil {
//		log.Error("register Junior", zap.Error(err))
//		return err
//	}
//	return nil
//}
//
//// ValidIdCard 验证证件信息是否已存在
//func ValidIdCard(orm *gorm.DB, idcardtype int, idcard string) (resp models.AdIdentification) {
//	// sql := `SELECT
//	// 			id, userid, name, surname, middlename, birthdate, countryid, city, address, zipcode, idcardtype, idcard,
//	// 			idcardimage1, idcardimage2, idcardvideo, verifyfile, idcardlevel, idcardstate, verifytype,
//	// 			createtime, verifytime, reason, videocode, faceimage1, faceimage2, accountid, workid,
//	// 			idcreditails, selfiecredential, facemapcredential
//	// 		FROM ad_identification WHERE  idcardtype = $1 AND idcard = $2 `
//	// err := dbhelper.MasterPgdb.Get(&resp, sql, idcardtype, idcard)
//	err := orm.Model(resp).Where("idcard_type =? AND idcard=?", idcardtype, idcard).Error
//
//	if err != nil {
//		log.Error("ValidIdCard : ", zap.Error(err))
//		return
//	}
//	return resp
//}
//
//// UpdateJunior 更新初级认证
//func UpdateJunior(orm *gorm.DB, ident dto.IdentificationJuniorReq) error {
//	// updateSql := `UPDATE
//	//                    ad_identification
//	//               SET
//	//                    name = :name,surname = :surname,middlename = :middlename,
//	//                    idcardlevel = 1,idcardstate = 1,birthdate = :birthdate,
//	//                    countryid = :countryid,idcardtype = :idcardtype,idcard = :idcard
//	//               WHERE userid = :userid`
//
//	//dbhelper.MasterPgdb.NamedExecTx(updateSql, &ident, tx);
//	if err := orm.Model(models.AdIdentification{}).Where("user_id =?", ident.UserId).Updates(map[string]interface{}{
//		"name": ident.Name, "surname": ident.Surname, "middle_name": ident.MiddleName,
//		"idcard_level": 1, "idcard_state": 1, "birth_date": ident.BirthDate, "country_id": ident.CountryId,
//		"idcard_type": ident.IdCardType, "idcard": ident.IdCard,
//	}).Error; err != nil {
//		log.Error("UpdateJunior", zap.Error(err))
//		return err
//	}
//	return nil
//}
//
//// UpdateMiddle 中级认证
//func UpdateMiddle(orm *gorm.DB, ident dto.IdentificationMiddleReq) error {
//	// updateSql := `UPDATE
//	//                   ad_identification
//	//               SET
//	//                   idcardimage1 = :idcardimage1,idcardimage2 = :idcardimage2,idcardvideo = :idcardvideo,
//	//                   idcardlevel = 2,idcardstate = :idcardstate,verifytype = :verifytype,videocode= :videocode,
//	//                   reason = :reason,verifytime = :verifytime,faceimage1 = :faceimage1,faceimage2 = :faceimage2,
//	//                   accountid = :accountid,workid = :workid,idcreditails = :idcreditails,
//	//                   selfiecredential = :selfiecredential,facemapcredential = :facemapcredential
//	//               WHERE userid = :userid`
//	// dbhelper.MasterPgdb.NamedExecTx(updateSql, &ident, tx)
//
//	if err := orm.Model(models.AdIdentification{}).Where("user_id=?", ident.UserId).Updates(map[string]interface{}{
//		"idcard_image1": ident.IdCardImage1, "idcard_image2": ident.IdCardImage2,
//		"idcard_video": ident.IdCardVideo, "idcard_level": 2, "idcard_state": ident.IdCardState,
//		"verify_type": ident.VerifyType, "video_code": ident.VideoCode, "reason": ident.Reason,
//		"verify_time": ident.VerifyTime, "face_image1": ident.FaceImage1, "face_image2": ident.FaceImage2,
//		"account_id": ident.AccountId, "work_id": ident.WorkFlowExecutionId, "id_creditails": ident.IdCreditails,
//		"selfile_credential": ident.SelfieCredential, "facemap_credential": ident.FacemapCredential,
//	}).Error; err != nil {
//		log.Error("UpdateMiddle", zap.Error(err))
//		return err
//	}
//	return nil
//}
//
//// UpdateMiddleByThird d
//func UpdateMiddleByThird(orm *gorm.DB, ident dto.IdentificationMiddleReq) error {
//	// updateSql := `UPDATE
//	//                   ad_identification
//	//               SET
//	//                   idcardimage1 = :idcardimage1,idcardimage2 = :idcardimage2,idcardstate = :idcardstate,
//	//                   reason = :reason,verifytime = :verifytime,faceimage1 = :faceimage1,faceimage2 = :faceimage2
//
//	//               WHERE userid = :userid`
//
//	// dbhelper.MasterPgdb.NamedExecTx(updateSql, &ident, tx)
//
//	if err := orm.Model(models.AdIdentification{}).Where("user_id=?", ident.UserId).Updates(map[string]interface{}{
//		"idcard_image1": ident.IdCardImage1, "idcard_image2": ident.IdCardImage2, "idcard_state": ident.IdCardState,
//		"reason": ident.Reason, "verify_time": ident.VerifyTime, "face_image1": ident.FaceImage1, "face_image2": ident.FaceImage2,
//	}).Error; err != nil {
//		log.Error("UpdateMiddleByThird", zap.Error(err))
//		return err
//	}
//	return nil
//}
//
//// UpdateSenior 用户高级认证
//func UpdateSenior(orm *gorm.DB, userId int) error {
//	// updateSql := `UPDATE ad_identification SET idcardlevel = 3,idcardstate = 1 WHERE userid = $1`
//	// dbhelper.MasterPgdb.ExecTx(updateSql, tx, userId)
//
//	if err := orm.Model(models.AdIdentification{}).Where("user_id=?", userId).Updates(map[string]interface{}{
//		"idcard_level": 3, "idcard_state": 1,
//	}).Error; err != nil {
//		log.Error("UpdateSenior", zap.Error(err))
//		return err
//	}
//	return nil
//}
//
//// GetIdentification 获取认证信息
//func GetIdentification(orm *gorm.DB, userId int) (models.AdIdentification, error) {
//	// sqlInfo := `SELECT id, userid, name, surname, middlename, birthdate, countryid, city,
//	// 	address, zipcode, idcardtype, idcard, idcardimage1, idcardimage2, idcardvideo,
//	// 	 verifyfile, idcardlevel, idcardstate, verifytype,createtime,verifytime,reason,
//	// 	 accountid, workid ,
//	// 	 idcreditails ,
//	// 	 selfiecredential ,
//	// 	 facemapcredential
//	//     FROM ad_identification WHERE userid = $1`
//
//	//dbhelper.MasterPgdb.Get(&ident, sqlInfo, userId)
//	var ident models.AdIdentification
//	err := orm.Model(ident).Where("user_id =?", userId).First(&ident).Error
//
//	if err != nil && !errors.Is(err, gorm.ErrRecordNotFound) {
//		log.Error("get Identification", zap.Error(err))
//		return ident, err
//	}
//	return ident, nil
//}
//
//// UpdateJuniorMidAuth 标准(中级)认证审核
//// func UpdateJuniorMidAuth(req dto.IdentJuniorMiddleAuthReq, tx *sqlx.Tx) error {
//// 	updateSql := `UPDATE
////                      ad_identification
////                   SET
////                      idcardstate = :idcardstate,reason = :reason,verifytime = :verifytime
////                   WHERE userid = :userid`
//// 	if _, err := dbhelper.MasterPgdb.NamedExecTx(updateSql, &req, tx); err != nil {
//// 		log.Error("UpdateJuniorMidAuth", zap.Error(err))
//// 		return err
//// 	}
//// 	return nil
//// }
//
//// UpdateSeniorAuth 高级认证审核
//// func UpdateSeniorAuth(req dto.IdentificationSeniorReq, tx *sqlx.Tx) error {
//// 	updateSql := `UPDATE
////                      ad_identification
////                   SET
////                      city = :city,address = :address,zipcode = :zipcode,
////                      idcardlevel = 3,idcardstate = :idcardstate,verifytype = 2,
////                      verifyfile = :verifyfile,reason = :reason,verifytime = :verifytime
////                   WHERE userid = :userid`
//// 	if _, err := dbhelper.MasterPgdb.NamedExecTx(updateSql, &req, tx); err != nil {
//// 		log.Error("UpdateSeniorAuth", zap.Error(err))
//// 		return err
//// 	}
//// 	return nil
//// }
//
//// IdentDetail 认证详情
//// func IdentDetail(userid int) (detail dto.IdentDetailResp, err error) {
//// 	sql := `SELECT
////                 userid,name,surname,middlename,idcardtype,idcard,idcardimage1,
////                 idcardimage2,birthdate,idcardvideo,address,city,zipcode,
////                 verifyfile,reason,videocode,faceimage1,faceimage2,ad_user.phone,
////                 ad_user.useraccount, to_char(ad_user.createtime,'yyyy-MM-dd hh24:MI:ss') as createtime,ad_user.useremail, ad_user.area,ad_country.namezh
////             FROM
////                 ad_identification
////                 JOIN ad_user ON ad_user.id = ad_identification.userid
////                 JOIN ad_country ON ad_country.id = ad_identification.countryid
////             WHERE ad_identification.userid = $1`
//// 	err = dbhelper.MasterPgdb.Get(&detail, sql, userid)
//// 	if err != nil {
//// 		log.Error("IdentDetail", zap.Error(err))
//// 	}
//// 	return
//// }
