export interface AssetConfiguration {
    deviceId: string;
    drmType: string;
    licensingUri: string;
    manifestUri: string;
    streamType: string;
}

export function getAssetConfigurationFromQueryString(queryString): AssetConfiguration {
    const manifestUri = decodedQueryParameter(queryString, 'manifestUri');
    const licensingUri = decodedQueryParameter(queryString, 'licensingUri');
    const deviceId = decodedQueryParameter(queryString, 'deviceId');
    const drmType = decodedQueryParameter(queryString, 'drmType');
    const streamType = decodedQueryParameter(queryString, 'streamType');
    return {
        deviceId,
        drmType,
        manifestUri,
        licensingUri,
        streamType,
    };
}

function decodedQueryParameter(queryString: string, parameterName: string): string {
    const parameterNameRegex = `${parameterName}=([^&]*)`;
    const match = queryString.match(parameterNameRegex);
    if (!match) {
        return '';
    }
    return decodeURIComponent(match[1]);
}
