import { inject, Injectable } from '@angular/core'; import { HttpClient } from '@angular/common/http'; import { Observable } from 'rxjs'; import { environment } from '../../../../environments/environment'; export interface AdminOrderItem { id: string; originalFilename: string; materialCode: string; colorCode: string; filamentVariantId?: number; filamentVariantDisplayName?: string; filamentColorName?: string; filamentColorHex?: string; quality?: string; nozzleDiameterMm?: number; layerHeightMm?: number; infillPercent?: number; infillPattern?: string; supportsEnabled?: boolean; quantity: number; printTimeSeconds: number; materialGrams: number; unitPriceChf: number; lineTotalChf: number; } export interface AdminOrder { id: string; orderNumber: string; status: string; paymentStatus?: string; paymentMethod?: string; customerEmail: string; totalChf: number; createdAt: string; isCadOrder?: boolean; sourceRequestId?: string; cadHours?: number; cadHourlyRateChf?: number; cadTotalChf?: number; printMaterialCode?: string; printNozzleDiameterMm?: number; printLayerHeightMm?: number; printInfillPattern?: string; printInfillPercent?: number; printSupportsEnabled?: boolean; items: AdminOrderItem[]; } export interface AdminUpdateOrderStatusPayload { status: string; } @Injectable({ providedIn: 'root', }) export class AdminOrdersService { private readonly http = inject(HttpClient); private readonly baseUrl = `${environment.apiUrl}/api/admin/orders`; listOrders(): Observable { return this.http.get(this.baseUrl, { withCredentials: true }); } getOrder(orderId: string): Observable { return this.http.get(`${this.baseUrl}/${orderId}`, { withCredentials: true, }); } updatePaymentMethod(orderId: string, method: string): Observable { return this.http.post( `${this.baseUrl}/${orderId}/payments/confirm`, { method }, { withCredentials: true }, ); } updateOrderStatus( orderId: string, payload: AdminUpdateOrderStatusPayload, ): Observable { return this.http.post( `${this.baseUrl}/${orderId}/status`, payload, { withCredentials: true }, ); } downloadOrderItemFile( orderId: string, orderItemId: string, ): Observable { return this.http.get( `${this.baseUrl}/${orderId}/items/${orderItemId}/file`, { withCredentials: true, responseType: 'blob', }, ); } downloadOrderConfirmation(orderId: string): Observable { return this.http.get(`${this.baseUrl}/${orderId}/documents/confirmation`, { withCredentials: true, responseType: 'blob', }); } downloadOrderInvoice(orderId: string): Observable { return this.http.get(`${this.baseUrl}/${orderId}/documents/invoice`, { withCredentials: true, responseType: 'blob', }); } }