import { RdDPossessionV2 } from "../combat/rdd-possession-v2.mjs"
import { DIFF, ROLL_TYPE_POSSESSION } from "./roll-constants.mjs"
import { RollType } from "./roll-type.mjs"

export class RollTypePossession extends RollType {
  get code() { return ROLL_TYPE_POSSESSION }
  get name() { return "Posséder" }

  prepare(rollData) {
    rollData.type.possession = RdDPossessionV2.getTypePossessionAction(rollData.active, rollData.opponent, rollData.type.possession?.action)
  }

  title(rollData) {
    return RdDPossessionV2.actionTitle(rollData.type.possession.action)
  }

  isOpposed(rollData) { return rollData.opponent != undefined }

  onSelect(rollData) {
    this.setDiffType(rollData, this.isAttaque(rollData) ? DIFF.ATTAQUE : DIFF.DEFENSE)
  }

  isEntite(rollData) {
    return rollData.active.actor.isEntiteNonIncarnee()
  }

  isAttaque(rollData) {
    return RdDPossessionV2.isAttaque(rollData.type.possession.action)
  }
}