// This file was autogenerated. Please do not change.
// All changes will be overwrited on commit.
export interface IAddressInfo {
    ip: string;
    port: number;
}

export default class AddressInfo {
    readonly _ip: string;

    /**
     * Description: undefined
     * Example: 127.0.0.1
     */
    get ip(): string {
        return this._ip;
    }

    static ipValidate(ip: string): boolean {
        return typeof ip === 'string' && !!ip.trim();
    }

    readonly _port: number;

    /**
     * Description: undefined
     * Example: 53
     */
    get port(): number {
        return this._port;
    }

    static portValidate(port: number): boolean {
        return typeof port === 'number';
    }

    constructor(props: IAddressInfo) {
        this._ip = props.ip.trim();
        this._port = props.port;
    }

    serialize(): IAddressInfo {
        const data: IAddressInfo = {
            ip: this._ip,
            port: this._port,
        };
        return data;
    }

    validate(): string[] {
        const validate = {
            ip: typeof this._ip === 'string' && !this._ip ? true : this._ip,
            port: typeof this._port === 'number',
        };
        const isError: string[] = [];
        Object.keys(validate).forEach((key) => {
            if (!(validate as any)[key]) {
                isError.push(key);
            }
        });
        return isError;
    }

    update(props: Partial<IAddressInfo>): AddressInfo {
        return new AddressInfo({ ...this.serialize(), ...props });
    }
}
