import { Dictionary } from "@insite/client-framework/Common/Types";
import { ProductRecommendationModel } from "@insite/client-framework/Services/ProductRecommendationsService";
import ApplicationState from "@insite/client-framework/Store/ApplicationState";
import { getSession, getSettingsCollection } from "@insite/client-framework/Store/Context/ContextSelectors";

export function enableProductRecommendations(state: ApplicationState): boolean {
    return getSettingsCollection(state).productSettings.enableProductRecommendations;
}

export function enablePeeriusRequestsConsoleLogs(state: ApplicationState): boolean {
    return getSettingsCollection(state).productSettings.enablePeeriusRequestsConsoleLogs;
}

export function peeriusApiVersion(state: ApplicationState): string {
    return getSettingsCollection(state).productSettings.peeriusApiVersion;
}

export function peeriusSiteName(state: ApplicationState): string {
    return getSettingsCollection(state).productSettings.peeriusSiteName;
}

export function peeriusTrackingUrl(state: ApplicationState): string {
    return getSettingsCollection(state).productSettings.peeriusTrackingUrl;
}

export function generateGeneralPrepare(
    state: ApplicationState,
    customAttributes?: Dictionary<any>,
): ProductRecommendationModel {
    const session = getSession(state);
    const locationId = session?.shipToId || "";
    const customerId = session?.billToId || "";
    const segmentIds = session?.personas?.map(persona => persona.name) || [];

    return {
        lang: session?.language?.languageCode || "",
        channel: "web",
        user: {
            id: session?.userName || "",
        },
        recContent: "refCodeOnly",
        customAttributes: {
            locationId,
            ...customAttributes,
        },
        customer: {
            customerId,
            segmentIds,
        },
    };
}
