import httpClient from '@/shared/config/api/httpClient';
import { API_URLS } from '@/shared/config/api/URLs';
import { AxiosResponse } from 'axios';

export interface OrderList {
  total: number;
  page: number;
  page_size: number;
  total_pages: number;
  has_next: boolean;
  has_previous: boolean;
  results: OrderListRes[];
}

export interface OrderListRes {
  id: string;
  order_number: number;
  status: 'NEW' | 'DONE';
  total_price: number;
  payment_type: 'CASH' | 'ACCOUNT_NUMBER';
  delivery_type: 'YandexGo' | 'DELIVERY_COURIES' | 'PICKUP';
  delivery_price: number;
  contact_number: string;
  comment: string;
  name: string;
  items: [
    {
      id: string;
      product: {
        id: string;
        name: string;
        image: string;
        price: number;
        description: string;
        unity: string;
        min_quantity: number;
        is_active: true;
        liked: string;
        brand: string;
        return_date: string;
        expires_date: string;
        manufacturer: string;
        volume: string;
        images: [
          {
            id: string;
            image: string;
          },
        ];
      };
      price: number;
      quantity: number;
      created_at: string;
    },
  ];
  created_at: string;
}

export const order_api = {
  async list(params: {
    page: number;
    page_size: number;
  }): Promise<AxiosResponse<OrderList>> {
    const res = await httpClient.get(API_URLS.OrderList, { params });
    return res;
  },
};
