// This file was autogenerated. Please do not change.
// All changes will be overwrited on commit.
export interface IAccessList {
    allowed_clients?: string[];
    blocked_hosts?: string[];
    disallowed_clients?: string[];
}

export default class AccessList {
    readonly _allowed_clients: string[] | undefined;

    /** */
    get allowedClients(): string[] | undefined {
        return this._allowed_clients;
    }

    readonly _blocked_hosts: string[] | undefined;

    /** */
    get blockedHosts(): string[] | undefined {
        return this._blocked_hosts;
    }

    readonly _disallowed_clients: string[] | undefined;

    /** */
    get disallowedClients(): string[] | undefined {
        return this._disallowed_clients;
    }

    constructor(props: IAccessList) {
        if (props.allowed_clients) {
            this._allowed_clients = props.allowed_clients;
        }
        if (props.blocked_hosts) {
            this._blocked_hosts = props.blocked_hosts;
        }
        if (props.disallowed_clients) {
            this._disallowed_clients = props.disallowed_clients;
        }
    }

    serialize(): IAccessList {
        const data: IAccessList = {
        };
        if (typeof this._allowed_clients !== 'undefined') {
            data.allowed_clients = this._allowed_clients;
        }
        if (typeof this._blocked_hosts !== 'undefined') {
            data.blocked_hosts = this._blocked_hosts;
        }
        if (typeof this._disallowed_clients !== 'undefined') {
            data.disallowed_clients = this._disallowed_clients;
        }
        return data;
    }

    validate(): string[] {
        const validate = {
            allowed_clients: !this._allowed_clients ? true : this._allowed_clients.reduce((result, p) => result && typeof p === 'string', true),
            disallowed_clients: !this._disallowed_clients ? true : this._disallowed_clients.reduce((result, p) => result && typeof p === 'string', true),
            blocked_hosts: !this._blocked_hosts ? true : this._blocked_hosts.reduce((result, p) => result && typeof p === 'string', true),
        };
        const isError: string[] = [];
        Object.keys(validate).forEach((key) => {
            if (!(validate as any)[key]) {
                isError.push(key);
            }
        });
        return isError;
    }

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