import { Injectable } from '@angular/core';
import { IOrder } from '../models/order.interface';

@Injectable({
  providedIn: 'root',
})
export class OrderService {
  
  private currentOrder: IOrder = {};

  public getOrder(): IOrder {
    return this.currentOrder;
  }
  
  public updateOrder(partialOrder: Partial<IOrder>): void {
    this.currentOrder = { ...this.currentOrder, ...partialOrder };
  }

  public placeOrder(): string {
    // Logic to send order

    const finalOrder = this.getOrder();

    const shippingID = "SC-" + Math.floor(Math.random() * 1000000).toString().padStart(6, '0');
    this.updateOrder({ shippingNumber: shippingID });

    console.log('Order placed:', this.getOrder());

    return shippingID;
  }
}
