import { MediaService, } from '../../../../core/backend-api/index.js';
import { tryExecute } from '../../../../core/resources/index.js';
/**
 * A server data source for Media Validation
 */
export class UmbMediaValidationServerDataSource {
    #host;
    constructor(host) {
        this.#host = host;
    }
    /**
     * Validate a new Media on the server
     * @param {UmbMediaDetailModel} model - Media Model
     * @param {UmbEntityUnique} parentUnique - Parent Unique
     * @returns {*}
     */
    async validateCreate(model, parentUnique = null) {
        if (!model)
            throw new Error('Media is missing');
        if (!model.unique)
            throw new Error('Media unique is missing');
        if (parentUnique === undefined)
            throw new Error('Parent unique is missing');
        // TODO: make data mapper to prevent errors
        const body = {
            id: model.unique,
            parent: parentUnique ? { id: parentUnique } : null,
            mediaType: { id: model.mediaType.unique },
            values: model.values,
            variants: model.variants,
        };
        // Maybe use: tryExecuteAndNotify
        const { data, error } = await tryExecute(this.#host, MediaService.postMediaValidate({
            body,
        }), {
            disableNotifications: true,
        });
        if (data && typeof data === 'string') {
            return { data };
        }
        return { error };
    }
    /**
     * Validate a existing Media
     * @param {UmbMediaDetailModel} model - Media Model
     * @param {Array<UmbVariantId>} variantIds - Variant Ids
     * @returns {Promise<*>} - The response from the server
     */
    async validateUpdate(model, 
    // eslint-disable-next-line @typescript-eslint/no-unused-vars
    variantIds) {
        if (!model.unique)
            throw new Error('Unique is missing');
        //const cultures = variantIds.map((id) => id.culture).filter((culture) => culture !== null) as Array<string>;
        // TODO: make data mapper to prevent errors
        const body = {
            values: model.values,
            variants: model.variants,
        };
        // Maybe use: tryExecuteAndNotify
        const { data, error } = await tryExecute(this.#host, MediaService.putMediaByIdValidate({
            path: { id: model.unique },
            body,
        }), {
            disableNotifications: true,
        });
        if (data && typeof data === 'string') {
            return { data };
        }
        return { error };
    }
}
