import { BaseController } from '@/api/BaseController';
import { RequestOption } from '@/common/http/types';
import { ANY_OBJECT } from '@/types/generic';
import { TableData } from '@/common/types/table';
import { useUrlBuilder } from '@/common/hooks/useUrl';
import DeliveryOrder from '@/types/table/deliveryOrder';
import { DeliveryOrderItemsData } from '@/api/generated/deliveryOrderItemsController';
import { API_CONTEXT } from '../config';

const { buildGetUrl } = useUrlBuilder();

export interface DeliveryOrderData extends DeliveryOrder {
  deliveryOrderItemsList?: DeliveryOrderItemsData[];
  __cascade_add_temp_id__?: string | number | undefined;
}

export default class DeliveryOrderController extends BaseController {
  static list(params: ANY_OBJECT, httpOptions?: RequestOption) {
    return super.post<TableData<DeliveryOrderData>>(API_CONTEXT + '/app/deliveryOrder/list', params, httpOptions);
  }
  static view(params: ANY_OBJECT, httpOptions?: RequestOption) {
    return super.get<DeliveryOrderData>(API_CONTEXT + '/app/deliveryOrder/view', params, httpOptions);
  }
  static export(params: ANY_OBJECT, fileName: string) {
    return super.download(API_CONTEXT + '/app/deliveryOrder/export', params, fileName);
  }
  static import(params: ANY_OBJECT) {
    return super.upload(API_CONTEXT + '/app/deliveryOrder/import', params);
  }
  static printUrl(params: ANY_OBJECT) {
    return buildGetUrl(API_CONTEXT + '/app/deliveryOrder/print', params);
  }
  static add(params: ANY_OBJECT, httpOptions?: RequestOption) {
    return super.post(API_CONTEXT + '/app/deliveryOrder/add', params, httpOptions);
  }
  static update(params: ANY_OBJECT, httpOptions?: RequestOption) {
    return super.post(API_CONTEXT + '/app/deliveryOrder/update', params, httpOptions);
  }
  static delete(params: ANY_OBJECT, httpOptions?: RequestOption) {
    return super.post(API_CONTEXT + '/app/deliveryOrder/delete', params, httpOptions);
  }
  static deleteBatch(params: ANY_OBJECT, httpOptions?: RequestOption) {
    return super.post(API_CONTEXT + '/app/deliveryOrder/deleteBatch', params, httpOptions);
  }
}
