// Questo file fa parte di MyTown.
// MyTown è software libero: puoi ridistribuirlo e/o modificarlo secondo
// i termini della GNU Affero General Public License come pubblicata dalla
// Free Software Foundation, versione 3.
// Distribuito senza ALCUNA GARANZIA; vedi la GNU AGPL v3 per i dettagli.
// Copyright (C) Kondor Consulting & Services S.r.l.
// SPDX-License-Identifier: AGPL-3.0-or-later

export interface DocumentPage {
	imageDataUrl: string;
	fileName: string;
	timestamp: Date;
}

export interface DocumentScan {
	id?: number;
	pages: DocumentPage[];
	status: 'pending' | 'processing' | 'completed' | 'error';
	result?: DocumentScanResult;
}

export interface DocumentScanResult {
	success: boolean;
	data?: any;
	errorMessage?: string;
}

export interface DocumentScanRequest {
	image: string; // Base64 encoded image
	fileName: string;
	mimeType: string;
}

export interface DocumentScanResponse {
	success: boolean;
	documentId?: number;
	extractedData?: any;
	errorMessage?: string;
}

/**
 * Upload AI dell'utente (documentary/file_upload).
 * Stato: 0=non elaborato, 1=in elaborazione, 2=completato, -1=errore, 99=archiviato.
 */
export interface MyUploadDTO {
	fu_id: number;
	fu_fui_id?: number;
	fu_ft_id?: number;
	fu_path?: string;
	fu_name?: string;
	fu_ai_status: number;
	fu_fg_id?: number;
	fu_dt_ins?: string;
}

/**
 * Riga unificata mostrata in "I miei DDT": può essere un DDT completo o un upload
 * ancora in elaborazione (kind='pending').
 */
export interface HistoryRow {
	kind: 'ddt' | 'pending';
	fuId?: number;
	ddt?: TransportDocumentDTO;
	upload?: MyUploadDTO;
}

export interface TransportDocumentItemDTO {
	id?: number;
	documentId?: number;
	code?: string;
	description?: string;
	quantity?: number;
	price?: number;
	discount?: number;
	amount?: number;
	vat?: number;
	invoiceId?: number;
}

export interface TransportDocumentDTO {
	id: number;
	supplierId?: number;
	fuId?: number;
	contrattoId?: number;
	number?: string;
	dateInsert?: string;
	dateDoc?: string;
	causal?: string;
	vector?: string;
	weight?: number;
	numPackages?: number;
	supplierName?: string;
	supplierVatNumber?: string;
	destinationAddress?: string;
	importo?: number;
	drflId?: number;
	cmpId?: number;
	wsId?: number;
	note?: string;
	path?: string;
	items?: TransportDocumentItemDTO[];
	worksite?: { id?: number; name?: string; address?: string } | null;
	sup?: { id?: number; name?: string } | null;
	totalrows?: number;
}
