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

export interface OrderList {
  id: number;
  user: number;
  comment: string;
  delivery_date: string;
  items: OrderItem[];
}

export default interface OrderItem {
  id: number;
  quantity: number;
  price: string;
  product: {
    id: number;
    images: { id: number; images: string | null }[];
    liked: false;
    meansurement: null | string;
    inventory_id: null | string;
    product_id: string;
    code: string;
    name: string;
    short_name: string;
    weight_netto: null | number;
    weight_brutto: null | number;
    litr: null | number;
    box_type_code: null | number;
    box_quant: null | number;
    groups: {
      id: number;
      name: string;
    }[];
    state: 'A' | 'P';
    barcodes: string;
    article_code: null | string;
    marketing_group_code: null | string;
    inventory_kinds: {
      id: number;
      name: string;
    }[];

    sector_codes: [];
    prices: {
      id: number;
      price: string;
      price_type: {
        id: number;
        name: string;
        code: string;
      };
    }[];

    payment_type: null | string;
    balance: number;
    updated_at: string;
  };
}

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(): Promise<AxiosResponse<OrderList[]>> {
    const res = await httpClient.get(API_URLS.OrderList);
    return res;
  },
};
