import { Brand, Data, Effect } from "effect";
export const SVGString = Brand.refined(isValidSVG, () => Brand.error('SVG data is malformed'));
export class BrandValidationError extends Data.TaggedError('BrandValidationError') {
    constructor(error, type) {
        super(new Error(`Brand validation failed for type ${type}.`, { cause: error }));
    }
}
export const createValidSVGString = (svg) => Effect.try({
    try: () => SVGString(svg),
    catch: error => new BrandValidationError(error, 'SVGString'),
});
function isValidSVG(svg) {
    if (typeof svg !== 'string') {
        return false;
    }
    try {
        const parser = new DOMParser();
        const doc = parser.parseFromString(svg, 'image/svg+xml');
        return doc.documentElement.nodeName === 'svg';
    }
    catch {
        return false;
    }
}
