/**
 * @copyright 2026 NHCarrigan
 * @license Naomi's Public License
 * @author Naomi Carrigan
 */
import { Injectable, inject } from '@angular/core';
import {
  AchievementDefinition,
  AchievementProgress,
  UserAchievementSummary,
} from '@library/shared-types';
import { Observable } from 'rxjs';

import { ApiService } from './api.service';

@Injectable({
  providedIn: 'root',
})
export class AchievementService {
  private readonly api = inject(ApiService);

  /**
   * Get all achievement definitions.
   */
  getAchievementDefinitions(): Observable<AchievementDefinition[]> {
    return this.api.get<AchievementDefinition[]>('/achievements/definitions');
  }

  /**
   * Get a specific achievement definition by key.
   */
  getAchievementDefinition(key: string): Observable<AchievementDefinition> {
    return this.api.get<AchievementDefinition>(`/achievements/definitions/${key}`);
  }

  /**
   * Get current user's achievement summary.
   */
  getCurrentUserSummary(): Observable<UserAchievementSummary> {
    return this.api.get<UserAchievementSummary>('/achievements/summary');
  }

  /**
   * Get current user's achievement progress.
   */
  getCurrentUserProgress(): Observable<AchievementProgress[]> {
    return this.api.get<AchievementProgress[]>('/achievements/progress');
  }

  /**
   * Get another user's achievement summary.
   */
  getUserSummary(userId: string): Observable<UserAchievementSummary> {
    return this.api.get<UserAchievementSummary>(`/achievements/users/${userId}/summary`);
  }

  /**
   * Get another user's achievement progress.
   */
  getUserProgress(userId: string): Observable<AchievementProgress[]> {
    return this.api.get<AchievementProgress[]>(`/achievements/users/${userId}/progress`);
  }
}
