import { DateTime, Duration } from 'luxon'
import { FluidType } from 'enum/fluid.enum'

export enum TypeChallenge {
  CHALLENGE = 0,
  ACHIEVEMENT = 1,
}

export class ChallengeType {
  id: string
  type: TypeChallenge
  title: string
  description: string
  level: number
  duration: Duration
  fluidTypes: FluidType[]
  availableEcogestures: EcogestureType[]

  constructor(
    id: string,
    type: TypeChallenge,
    title: string,
    description: string,
    level: number,
    duration: Duration,
    fluidTypes: FluidType[],
    availaibleEcogestures: EcogestureType[]
  ) {
    this.id = id
    this.type = type
    this.title = title
    this.description = description
    this.level = level
    this.duration = duration
    this.fluidTypes = fluidTypes
    this.availableEcogestures = availaibleEcogestures
  }
}

export class EcogestureType {
  id: string
  shortName: string
  longName: string
  shortDescription: string
  longDescription: string
  usage: string
  fluidTypes: FluidType[]
  nwh: number
  pack: number
  unlocked?: boolean

  constructor(
    id: string,
    shortName: string,
    longName: string,
    shortDescription: string,
    longDescription: string,
    usage: string,
    fluidTypes: FluidType[],
    nwh: number,
    pack: number,
    unlocked?: boolean
  ) {
    this.id = id
    this.shortName = shortName
    this.shortDescription = shortDescription
    this.longName = longName
    this.longDescription = longDescription
    this.usage = usage
    this.fluidTypes = fluidTypes
    this.nwh = nwh
    this.pack = pack
    this.unlocked = unlocked
  }
}

export enum ChallengeState {
  ONGOING = 0,
  FINISHED = 1,
  ABANDONED = 2,
}

export enum SelectView {
  BADGES = 0,
  ECOGESTURES = 1,
}

export enum BadgeState {
  FAILED = 0,
  SUCCESS = 1,
}

export class UserChallenge {
  id?: string
  startingDate: DateTime
  endingDate: DateTime
  state: ChallengeState
  selectedEcogestures: EcogestureType[]
  challengeType: ChallengeType | null
  maxEnergy: number
  currentEnergy: number
  badge: BadgeState | null

  constructor(
    startingDate: DateTime,
    endingDate: DateTime,
    state: ChallengeState,
    selectedEcogestures: EcogestureType[],
    challengeType: ChallengeType | null,
    maxEnergy: number,
    currentEnergy: number,
    badge: BadgeState | null,
    id?: string
  ) {
    this.startingDate = startingDate
    this.endingDate = endingDate
    this.state = state
    this.selectedEcogestures = selectedEcogestures
    this.challengeType = challengeType
    this.maxEnergy = maxEnergy
    this.currentEnergy = currentEnergy
    this.badge = badge
    this.id = id
  }

  public hasChallengeEnded(): boolean {
    // TO DO: logic to check if the challenges has ended
    return false
  }
}

export class UserProfile {
  id: string
  level: number
  challengeTypeHash: string
  ecogestureHash: string

  constructor(
    id: string,
    level: number,
    challengeTypeHash: string,
    ecogestureHash: string
  ) {
    this.id = id
    this.level = level
    this.challengeTypeHash = challengeTypeHash
    this.ecogestureHash = ecogestureHash
  }
}

// eslint-disable-next-line @typescript-eslint/interface-name-prefix
export interface IChallengeManager {
  getCurrentChallenge(withEcogestures?: boolean): Promise<UserChallenge | null>

  updateChallengeState(
    id: string,
    newState: number
  ): Promise<UserChallenge | null>
  cancelChallenge(id: string): Promise<UserChallenge | null>

  fulfillChallenge(challenge: UserChallenge): Promise<UserChallenge | null>

  startChallenge(
    challenge: ChallengeType,
    fluidTypes: FluidType[],
    selectedEcogestes: EcogestureType[]
  ): Promise<UserChallenge | null>

  getAvailableChallenges(
    fluidTypes?: FluidType[]
  ): Promise<ChallengeType[] | null>

  getUnlockedBadges(): Promise<ChallengeType[] | null>

  getUnlockedEcogestures(): Promise<EcogestureType[] | null>
}

// eslint-disable-next-line @typescript-eslint/interface-name-prefix
export interface IUserProfileManager {
  getUserProfile(): Promise<UserProfile | null>
}