import { createSelector } from "reselect";

import {
  DecorationUtils,
  rulesEngineSelectors,
} from "@dndbeyond/character-rules-engine/es";
import { RollContext } from "@dndbeyond/pocket-dimension-dice/types";

import { appEnvSelectors } from "./index";

export const getCharacterRollContext = createSelector(
  [
    appEnvSelectors.getCharacterId,
    rulesEngineSelectors.getName,
    rulesEngineSelectors.getDecorationInfo,
    rulesEngineSelectors.getUserId,
  ],
  (characterId, name, decorationInfo, userId): RollContext => {
    return {
      entityId: characterId ? characterId.toString() : "",
      entityType: "character",
      name: name?.toString(),
      avatarUrl:
        DecorationUtils.getAvatarInfo(decorationInfo).avatarUrl?.toString(),
      userId: String(userId),
    };
  }
);
