import { ModelMetadataCollection } from "../collections/model-metadata";
import { OdooFieldMetadata } from "../metadata/field-metadata";

export class FieldMetadataCollection<T extends { target?: Function | string, propertyName?: string }> extends ModelMetadataCollection<T> {

    /**
     *
     */
    filterRepeatedMetadatas(existsMetadatas: T[]): this {
        return this.filter(metadata => {
            return !existsMetadatas.find(fieldDocument => fieldDocument.propertyName === metadata.propertyName);
        });
    }

    /**
     *
     */
    findByProperty(propertyName: string): T {
        return this.items.find(item => item.propertyName === propertyName);
    }

    /**
     *
     */
    hasWithProperty(propertyName: string) {
        return !!this.findByProperty(propertyName);
    }

    /**
     * 
     */
    getNames() {
        return this.items.map((i: any) => {
            return i.fieldName;
        });
    }
}