// 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 type ReviewStatus = 'PUBBLICATA' | 'SEGNALATA' | 'NASCOSTA';
export type ReportReason = 'OFFENSIVA' | 'FALSA' | 'SPAM' | 'ALTRO';
/** Modulo sorgente della recensione (Fase A: solo APPUNTAMENTO). */
export type ReviewSource = 'APPUNTAMENTO' | 'PRENOTAZIONE' | 'ORDINE' | 'LUOGO';

export interface Review {
	rev_id: number;
	rev_source: ReviewSource;
	rev_source_id: number;
	rev_cmp_id: number;
	rev_service_type_id: number | null;
	/** Snapshot del contesto all'insert: nome servizio / risorsa / n. ordine / luogo. */
	rev_context_name?: string | null;
	/** Snapshot del colore categoria (solo APPUNTAMENTO). */
	rev_context_color?: string | null;
	rev_client_usr_id: number;
	rev_rating_quality: number;
	rev_rating_service: number;
	rev_rating_price: number;
	rev_rating_timeliness: number;
	rev_rating_overall: number;
	rev_title: string | null;
	rev_text: string | null;
	rev_status: ReviewStatus;
	rev_created_at: string;
	client_firstname?: string;
	client_lastname?: string;
	totalrows?: number;
}

export interface ReviewCategoryStat {
	service_type_id: number | null;
	service_type_name: string | null;
	service_type_color: string | null;
	avg_overall: number;
	count: number;
}

export interface ReviewStats {
	avg_overall: number | null;
	total_count: number;
	avg_quality: number | null;
	avg_service: number | null;
	avg_price: number | null;
	avg_timeliness: number | null;
	star5: number;
	star4: number;
	star3: number;
	star2: number;
	star1: number;
	by_category: ReviewCategoryStat[];
}

/** Criteri di valutazione (chiave campo + etichetta IT). */
export const ReviewCriteria: { key: 'rev_rating_quality' | 'rev_rating_service' | 'rev_rating_price' | 'rev_rating_timeliness'; label: string }[] = [
	{ key: 'rev_rating_quality', label: 'Qualità' },
	{ key: 'rev_rating_service', label: 'Servizio' },
	{ key: 'rev_rating_price', label: 'Prezzo' },
	{ key: 'rev_rating_timeliness', label: 'Puntualità' },
];

export const ReportReasonOptions: { label: string; value: ReportReason }[] = [
	{ label: 'Contenuto offensivo', value: 'OFFENSIVA' },
	{ label: 'Falsa / non autentica', value: 'FALSA' },
	{ label: 'Spam', value: 'SPAM' },
	{ label: 'Altro', value: 'ALTRO' },
];
