import { MediaService } from '../../../../core/backend-api/index.js';
import { tryExecute } from '../../../../core/resources/index.js';
/**
 * Server data source for the Media audit log
 * @class UmbAuditLogServerDataSource
 */
export class UmbMediaAuditLogServerDataSource {
    #host;
    /**
     * Creates an instance of UmbAuditLogServerDataSource.
     * @param {UmbControllerHost} host - The controller host for this controller to be appended to
     * @memberof UmbAuditLogServerDataSource
     */
    constructor(host) {
        this.#host = host;
    }
    /**
     * Get the audit log for a Media
     * @param {UmbAuditLogRequestArgs} args
     * @returns {*}
     * @memberof UmbMediaAuditLogServerDataSource
     */
    async getAuditLog(args) {
        const { data, error } = await tryExecute(this.#host, MediaService.getMediaByIdAuditLog({
            path: { id: args.unique },
            query: {
                orderDirection: args.orderDirection, // TODO: fix this type cast
                sinceDate: args.sinceDate,
                skip: args.skip,
                take: args.take,
            },
        }));
        if (data) {
            const mappedItems = data.items.map((item) => {
                return {
                    user: { unique: item.user.id },
                    timestamp: item.timestamp,
                    logType: item.logType, // TODO: fix this type cast
                    comment: item.comment,
                    parameters: item.parameters,
                };
            });
            return { data: { items: mappedItems, total: data.total } };
        }
        return { error };
    }
}
