/**
 * `ApiMember` is a GET /users row as Razorbooking_Admin_Data::team_table()
 * passes it on. `TeamRow` is the admin roster's row
 * (razorbooking-admin resources/js/features/team/types.ts), less what a site
 * key cannot read.
 */

export interface BusinessDay {
	day: string;
	closed: boolean;
	hours: { start_time: { slot: string }; end_time: { slot: string } }[];
}

export interface ApiMember {
	id: number;
	name: string;
	email: string;
	role: string;
	designation?: string | null;
	/** Their page on the booking site, `{site}/{slug}`. */
	slug?: string | null;
	description?: string | null;
	primary_phone?: string | null;
	can_take_bookings: boolean;
	is_active: boolean;
	avatar?: { original_url?: string } | null;
	/** Present only when the API answers `include=hours`: null = follows the business. */
	business_hours?: BusinessDay[] | null;
	on_leave?: boolean;
	/** Created from this site; the "invite them" note is still up. */
	show_invite_note?: boolean;
}

export interface TeamRow {
	key: string;
	id: number;
	name: string;
	initials: string;
	email: string;
	phone: string | null;
	role: string;
	roleLabel: string;
	designation: string | null;
	slug: string | null;
	avatarUrl?: string;
	/** undefined = the API did not say; null = follows business hours. */
	businessHours: BusinessDay[] | null | undefined;
	description: string | null;
	canTakeBookings: boolean;
	isActive: boolean;
	seg: 'active' | 'leave' | 'deactivated' | 'invited';
	/** A pending invitation, not yet a member: managed in RazorBooking. */
	invited: boolean;
	showInviteNote: boolean;
	/** A no_access member has no login; only their profile is edited here. */
	canSignIn: boolean;
}

/** A pending invitation (API `meta.invitations` with include=invitations). */
export interface ApiInvite {
	id: number;
	name?: string | null;
	email: string;
	role: string;
	expires_at?: string | null;
}

/** GET razorbooking/v1/team/table. */
export interface TeamTableProps {
	users: ApiMember[];
	invitations?: ApiInvite[];
	tenantBusinessHours: BusinessDay[] | null;
	permissions: string[];
	/** The booking site, for each member's public page. */
	siteUrl?: string | null;
}
