import type { PageParam, PageResult } from '@vben/request';

import { requestClient } from '#/api/request';

export namespace AssetDeliveryOrderApi {
  export interface DeliveryOrderVehicle {
    id?: number;
    taskVehicleId?: number;
    vehicleId?: number;
    plateNo?: string;
    vin?: string;
    brand?: string;
    model?: string;
    mileage?: number;
    hydrogenLevel?: number;
  }

  export interface DeliveryOrder {
    id?: number;
    orderCode?: string;
    taskId: number;
    taskCode?: string;
    contractId?: number;
    contractCode?: string;
    projectName?: string;
    customerId?: number;
    customerName?: string;
    deliveryDate: string;
    deliveryPerson: string;
    deliveryLocation?: string;
    authorizedPersonId?: number;
    authorizedPersonName?: string;
    authorizedPersonPhone?: string;
    authorizedPersonIdCard?: string;
    esignStatus?: number;
    deliveryPhotos?: string;
    inspectionRecordId?: number;
    status?: number;
    vehicles?: DeliveryOrderVehicle[];
    createTime?: Date;
  }
}

export function getDeliveryOrderPage(params: PageParam) {
  return requestClient.get<PageResult<AssetDeliveryOrderApi.DeliveryOrder>>(
    '/asset/delivery-order/page',
    { params },
  );
}

export function getDeliveryOrder(id: number) {
  return requestClient.get<AssetDeliveryOrderApi.DeliveryOrder>(
    `/asset/delivery-order/get?id=${id}`,
  );
}

export function createDeliveryOrder(data: AssetDeliveryOrderApi.DeliveryOrder) {
  return requestClient.post('/asset/delivery-order/create', data);
}

export function updateDeliveryOrder(data: AssetDeliveryOrderApi.DeliveryOrder) {
  return requestClient.put('/asset/delivery-order/update', data);
}

export function deleteDeliveryOrder(id: number) {
  return requestClient.delete(`/asset/delivery-order/delete?id=${id}`);
}

export function completeDeliveryOrder(id: number) {
  return requestClient.put(`/asset/delivery-order/complete?id=${id}`);
}
