import { EntitiesApi_GetEntityUsers } from "./generated/metadata-json-api/index.js";
/**
 * @internal
 */
export function isLiveFeatures(features) {
    return features?.live !== undefined;
}
/**
 * @internal
 */
export function isStaticFeatures(features) {
    return features?.static !== undefined;
}
export const tigerProfileClientFactory = (axios) => {
    return {
        getCurrent: async (_detailed) => {
            return ProfileApi_GetCurrent(axios, _detailed);
        },
        getCurrentWithDetails: async (_detailed) => {
            return ProfileApi_GetCurrentWithDetails(axios, _detailed);
        },
    };
};
// TODO: replace with direct call of TigerClient (once methods are generated from OpenAPI)
export async function ProfileApi_GetCurrent(axios, _detailed) {
    const response = await axios.get("/api/v1/profile");
    const deployment = response.headers?.["gooddata-deployment"];
    return {
        ...response.data,
        ...(deployment ? { deployment } : {}),
    };
}
export async function ProfileApi_GetCurrentWithDetails(axios, _detailed) {
    const response = await axios.get("/api/v1/profile");
    const profile = response.data;
    const deployment = response.headers?.["gooddata-deployment"];
    const details = await getUserDetails(axios, profile.userId);
    return {
        ...profile,
        ...details,
        ...(deployment ? { deployment } : {}),
    };
}
async function getUserDetails(axios, id) {
    const response = await EntitiesApi_GetEntityUsers(axios, "", {
        id,
    });
    const user = response.data;
    const firstName = user.data.attributes?.firstname;
    const lastName = user.data.attributes?.lastname;
    const email = user.data.attributes?.email;
    return {
        ...(firstName &&
            lastName && {
            name: `${firstName} ${lastName}`,
            firstName,
            lastName,
        }),
        ...(email && {
            email,
        }),
    };
}
//# sourceMappingURL=profile.js.map