import { Injectable, inject } from '@angular/core'; import { HttpClient } from '@angular/common/http'; import { Observable } from 'rxjs'; import { Challenge, DeclineChallengeRequest, ListChallengesResponse, SendChallengeRequest } from '../models/challenge.models'; @Injectable({ providedIn: 'root' }) export class ChallengeService { private readonly http = inject(HttpClient); private readonly challengeBaseUrl = '/api/challenge'; sendChallenge(username: string, request: SendChallengeRequest): Observable { return this.http.post( `${this.challengeBaseUrl}/${username}`, request ); } listChallenges(): Observable { return this.http.get( `${this.challengeBaseUrl}` ); } getChallenge(challengeId: string): Observable { return this.http.get( `${this.challengeBaseUrl}/${challengeId}` ); } acceptChallenge(challengeId: string): Observable { return this.http.post( `${this.challengeBaseUrl}/${challengeId}/accept`, {} ); } declineChallenge(challengeId: string, request?: DeclineChallengeRequest): Observable { return this.http.post( `${this.challengeBaseUrl}/${challengeId}/decline`, request || {} ); } cancelChallenge(challengeId: string): Observable { return this.http.post( `${this.challengeBaseUrl}/${challengeId}/cancel`, {} ); } }