/**
 * Minimal hand-written REST types.
 *
 * In M11 the full set is generated from docs/generated/openapi.json by
 * `npm run types:generate` (script TBD). This file holds the types every
 * screen imports so they remain stable while the generator lands.
 *
 * @package
 */

export interface Booking {
	id: number;
	status:
		| 'pending'
		| 'confirmed'
		| 'cancelled'
		| 'completed'
		| 'no_show'
		| 'paid';
	start_at: string;
	end_at: string;
	service_name: string;
	agent_name: string;
	customer_name: string;
	location_name?: string;
	total_minor?: number;
}

export interface Customer {
	id: number;
	display_name: string;
	email: string;
	phone?: string;
	created_at: string;
	bookings_count?: number;
	first_booking_at?: string | null;
}

export interface Service {
	id: number;
	name: string;
	status: 'active' | 'archived' | 'draft';
	duration_minutes: number;
	price_minor: number;
}

export interface Agent {
	id: number;
	display_name: string;
	timezone: string;
	status: 'active' | 'archived';
}

export interface Location {
	id: number;
	name: string;
	city?: string;
	status: 'active' | 'archived';
}

export type ThemeRadius =
	| 'var(--r-sm)'
	| 'var(--r-md)'
	| 'var(--r-lg)'
	| 'var(--r-full)';

export type ThemeFont = 'var(--font-sans)' | 'var(--font-mono)';

export interface BookingFormTheme {
	readonly accent: string;
	readonly radius: ThemeRadius;
	readonly font: ThemeFont;
	readonly density: 'compact' | 'comfortable';
	readonly scheme: 'light' | 'dark' | 'auto';
	readonly slot_style: 'bordered' | 'pill';
}

export interface CustomFormField {
	readonly key: string;
	readonly label: string;
	readonly type: 'text' | 'textarea' | 'select' | 'checkbox';
	readonly required: boolean;
	readonly options: readonly string[];
}

export interface BookingFormSettings {
	readonly require_phone?: boolean;
	readonly marketing_opt_in?: boolean;
	readonly cart_enabled?: boolean;
	readonly custom_fields?: readonly CustomFormField[];
}

export interface BookingFormSummary {
	id: number;
	name: string;
	slug: string;
	status: 'active' | 'inactive';
	step_count: number;
	accent: string;
	updated_at: string;
}

export interface BookingFormDetail extends BookingFormSummary {
	readonly uuid: string;
	readonly steps: readonly string[];
	readonly service_ids: readonly number[] | null;
	readonly agent_ids: readonly number[] | null;
	readonly location_ids: readonly number[] | null;
	readonly category_ids: readonly number[] | null;
	readonly settings: BookingFormSettings;
	readonly theme: BookingFormTheme;
	readonly created_at: string;
}

export interface BookingForm {
	id: number;
	name: string;
	status: 'active' | 'inactive';
	updated_at: string;
}

export interface NotificationTemplate {
	id: number;
	key: string;
	name: string;
	channel: 'email' | 'sms' | 'webhook';
	enabled: boolean;
}

export interface NotificationLogEntry {
	id: number;
	channel: string;
	recipient: string;
	subject: string;
	status: 'drafted' | 'sent' | 'failed';
	booking_id?: number;
	sent_at?: string;
	error?: string;
}

export interface AbandonedOrder {
	id: number;
	step_reached: string;
	service_name: string;
	contact: string;
	value_minor: number;
	updated_at: string;
}

export interface Automation {
	id: number;
	name: string;
	trigger: string;
	enabled: boolean;
}

export interface ActivityEntry {
	id: number;
	actor: string;
	subject: string;
	action: string;
	at: string;
}

export interface CalendarEvent {
	id: number;
	start_at: string;
	end_at: string;
	title: string;
	agent_name: string;
	service_name: string;
	status: string;
}

export interface DeliveryHealth {
	queue_depth?: number;
	last_run_at?: string;
	failed_recent?: number;
	cron_healthy?: boolean;
}

export interface SystemReport {
	plugin_version: string;
	php_version: string;
	wp_version: string;
	db_size_mb: number;
	queue_depth: number;
	active_theme: string;
}

export interface SettingsResponse {
	settings: Record< string, unknown >;
}

export interface WizardState {
	current_step: number;
	total_steps: number;
	business_name?: string;
	timezone?: string;
	currency?: string;
}

export interface PaginatedResponse< T > {
	items: T[];
	total: number;
	page: number;
	perPage: number;
}

// ---------------------------------------------------------------------------
// Mutation request bodies
// ---------------------------------------------------------------------------

export interface ServicePayload {
	name?: string;
	slug?: string;
	description?: string;
	short_description?: string;
	image_id?: number | null;
	colour?: string | null;
	status?: 'active' | 'archived' | 'draft';
	capacity_min?: number;
	capacity_max?: number;
	buffer_before_min?: number;
	buffer_after_min?: number;
	lead_time_min?: number | null;
	horizon_days?: number | null;
	slot_step_min?: number | null;
	deposit_type?: 'none' | 'fixed' | 'percent';
	deposit_value?: number;
	tax_class?: string | null;
	requires_approval?: boolean;
	sort_order?: number;
	meeting_provider?: 'none' | 'zoom' | 'google_meet' | 'microsoft_teams';
}

export interface ServiceDurationPayload {
	service_id?: number;
	duration_min?: number;
	price_minor?: number;
	currency?: string;
	label?: string | null;
	is_default?: boolean;
	sort_order?: number;
}

export interface ServiceExtraPayload {
	name?: string;
	description?: string | null;
	price_minor?: number;
	currency?: string;
	duration_min?: number;
	max_quantity?: number;
	status?: 'active' | 'inactive';
	sort_order?: number;
	service_id?: number;
	service_ids?: number[];
}

export interface ServiceExtra {
	id: number;
	name: string;
	description: string | null;
	price_minor: number;
	currency: string;
	duration_min: number;
	max_quantity: number;
	status: 'active' | 'inactive';
	sort_order: number;
	service_ids: number[];
}

export interface ServiceExtrasResponse {
	items: ServiceExtra[];
	total: number;
}

export interface AgentPayload {
	display_name?: string;
	email?: string;
	phone?: string | null;
	bio?: string | null;
	avatar_id?: number | null;
	timezone?: string;
	status?: 'active' | 'archived';
	colour?: string | null;
	sort_order?: number;
	wp_user_id?: number | null;
}

export interface LocationPayload {
	name?: string;
	slug?: string;
	address_line1?: string | null;
	address_line2?: string | null;
	city?: string | null;
	region?: string | null;
	postcode?: string | null;
	country?: string | null;
	latitude?: string | null;
	longitude?: string | null;
	timezone?: string;
	phone?: string | null;
	email?: string | null;
	status?: 'active' | 'inactive';
	colour?: string | null;
}

export interface CustomerPayload {
	first_name?: string;
	last_name?: string | null;
	email?: string;
	phone?: string | null;
	timezone?: string | null;
	locale?: string | null;
	notes?: string | null;
	marketing_consent?: boolean;
	status?: 'active' | 'archived';
}

// ---------------------------------------------------------------------------
// Mutation responses
// ---------------------------------------------------------------------------

export interface MutationResponse {
	id: number;
}

export interface DeleteResponse {
	deleted: boolean;
}

export interface ServiceDurationsResponse {
	items: ServiceDuration[];
	total: number;
}

export interface ServiceDuration {
	id: number;
	service_id: number;
	duration_min: number;
	price_minor: number;
	currency: string;
	label: string | null;
	is_default: boolean;
	sort_order: number;
}
