package com.reyun.saas.mob.openapi.dto;

import com.reyun.saas.common.exception.CustomException;
import com.reyun.saas.common.restResult.ResultCode;
import com.reyun.saas.common.util.IPUtils;
import io.swagger.annotations.ApiModel;
import lombok.Data;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;

import java.util.Set;

/**
 * @author: hanzepeng
 * @Date: 2022/02/14/10:58
 * @Description: OpenApi的rta白名单DTO对象
 */
@Data
@ApiModel(value = "RtaIpWhiteDTO", description = "openApi的rta白名单DTO对象")
public class RtaIpWhiteDTO {

    /**
     * 白名单ip
     */
    private Set<String> ips;


    /**
     * 校验参数
     */
    public void checkParam() {
        if(!CollectionUtils.isEmpty(this.ips)){
            for (String ip : ips) {
                //去空格
                if(!StringUtils.isEmpty(ip)){
                    ip = ip.trim();
                }
                //校验ip
                if(!IPUtils.iPCheck(ip)){
                    throw new CustomException(ResultCode.IP_FROMAT_ERROR);
                }
            }
        }
    }
}
