import { BaseDataDefinition } from "./BaseDataDefinition";
import { XDataType } from "../XDataType";
import { ValidationIssue } from "../../IDesignValidationProvider";
export class FileDataDefinition extends BaseDataDefinition {
    constructor() {
        super(...arguments);
        this.type = XDataType.FILE;
    }
    // we cannot convert into a file, it either is or is not.
    convert(_value) {
        return undefined;
    }
    verifyValueType(value) {
        if (value === undefined)
            return new ValidationIssue("Undefined Value");
        if (this.list) {
            if (!Array.isArray(value)) {
                return new ValidationIssue("is not an array of file");
            }
            for (let f of value) {
                if (!this.isFile(f)) {
                    return new ValidationIssue("array contains a non file object");
                }
            }
        }
        else {
            if (Array.isArray(value)) {
                return new ValidationIssue("is an array, expected single file");
            }
            if (!this.isFile(value)) {
                return new ValidationIssue("is not a file object");
            }
        }
    }
    isFile(v) {
        if (typeof v === "object") {
            return ((v.file && v.file instanceof File) ||
                (v.fileUrl &&
                    /^(http(s)?:\/\/.)?(www\.)?[-a-zA-Z0-9@:%._+~#=]{2,256}\.[a-z]{2,6}\b([-a-zA-Z0-9@:%_+.~#?&//=]*)/.test(v.fileUrl)));
        }
        return false;
    }
}
//# sourceMappingURL=FileDataDefinition.js.map