import { BaseMetadata } from '@/types/api/api-general';
import { Supplier } from '@/types/api/master-data/supplier';

type MovementWarehouse = {
  id: number;
  name: string;
  location: {
    id: number;
    name: string;
  } | null;
  area: {
    id: number;
    name: string;
  };
};

export type MovementDocument = {
  id: number;
  path: string;
  name: string;
  ext: string;
  size: number;
};

export type BaseMovement = {
  id: number;
  transfer_reason: string;
  transfer_date: string;
  source_warehouse: MovementWarehouse;
  destination_warehouse: MovementWarehouse;
  details: {
    id: number;
    product: {
      id: number;
      name: string;
    };
    quantity: number;
    before_quantity: number;
    after_quantity: number;
  }[];
  deliveries: {
    id: number;
    supplier: Supplier;
    vehicle_plate: string;
    driver_name: string;
    document_number: string;
    document_path: string;
    shipping_cost_item: number;
    shipping_cost_total: number;
    document?: MovementDocument;
    items: {
      id: number;
      stock_transfer_detail_id: number;
      quantity: number;
    }[];
  }[];
};

export type Movement = BaseMetadata & BaseMovement;

export type CreateMovementPayloadData = {
  transfer_reason: string;
  transfer_date: string;
  source_warehouse_id: number;
  destination_warehouse_id: number;
  products: {
    product_id: number;
    product_qty: number;
  }[];
  deliveries: {
    delivery_cost?: number;
    delivery_cost_per_item?: number;
    document_index?: number;
    driver_name?: string;
    vehicle_plate?: string;
    supplier_id?: number | null;
    products: {
      product_id: number;
      product_qty: number;
    }[];
  }[];
};

export type CreateMovementPayload = {
  data: CreateMovementPayloadData;
  documents?: File[];
};
