package com.fs.his.validator.cpw;

import com.fs.common.exception.CustomException;
import com.fs.his.domain.FsUserAddress;
import com.fs.his.dto.CPWUserBaseInfoAddDTO;
import com.fs.his.dto.CPWUserInfoCollectionAddDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * 用户信息主校验器---超拼网
 * 整合所有校验器
 */
@Component
public class UserInformationValidator {

    @Autowired
    private BaseInfoValidator baseInfoValidator;

    @Autowired
    private CollectionInfoValidator collectionInfoValidator;

    @Autowired
    private AddressValidator addressValidator;

    @Autowired(required = false)
    private CollectionInfoFixer collectionInfoFixer;

    /**
     * 只校验采集信息（用于 submitUserInformation 接口）
     */
    public void validateCollection(CPWUserInfoCollectionAddDTO collectionAddDTO) {
        // 先尝试修复格式问题
        if (collectionInfoFixer != null) {
            collectionInfoFixer.fix(collectionAddDTO);
        }
        collectionInfoValidator.validate(collectionAddDTO);
    }

    /**
     * 只校验用户基本信息（用于 createUserInformation 接口）
     */
    public void validateBaseInfo(CPWUserBaseInfoAddDTO baseInfoAddDTO) {
        baseInfoValidator.validate(baseInfoAddDTO);
    }

    /**
     * 同时校验用户基本信息和地址（可根据需要扩展）
     */
    public void validateUserAndAddress(FsUserAddress address) {
        if (address==null){
            throw new CustomException("请填写地址信息");
        }
        addressValidator.validate(address);
    }
}