// See https://svelte.dev/docs/kit/types#app.d.ts
// for information about these interfaces

// Kratos session identity
interface SessionIdentity {
	id: string;
	traits: {
		email?: string;
		name?: {
			first?: string;
			last?: string;
		};
		phone?: string;
		profile_type?: 'team' | 'customer';
	};
	metadata_public?: {
		django_profile_id?: string;
		customer_id?: string;
	};
}

// Kratos session
interface Session {
	id: string;
	active: boolean;
	identity: SessionIdentity;
	expires_at?: string;
	authenticated_at?: string;
}

// User from GraphQL Me query
interface User {
	__typename: 'TeamProfileType' | 'CustomerProfileType';
	id: string;
	fullName: string;
	email: string;
	phone?: string;
	role?: 'ADMIN' | 'TEAM_LEADER' | 'TEAM_MEMBER'; // TeamProfile only
	customers?: Array<{ id: string; name: string }>; // CustomerProfile only
}

declare global {
	namespace App {
		// interface Error {}
		interface Locals {
			cookie: string | null;
		}
		interface PageData {
			user: User | null;
		}
		// interface PageState {}
		// interface Platform {}
	}
}

export { Session, SessionIdentity, User };
