import { gql } from '@apollo/client/core';

export interface Event {
	id: string;
	eventType: string;
	entityType: string;
	entityId: string;
	actorType: string | null;
	actorId: string | null;
	metadata: Record<string, unknown> | null;
	timestamp: string;
	createdAt: string;
	description: string;
	actorProfile: {
		__typename: string;
		id: string;
		fullName: string;
	} | null;
}

export const RECENT_EVENTS_QUERY = gql`
	query RecentEvents($limit: Int, $offset: Int) {
		recentEvents(limit: $limit, offset: $offset) {
			id
			eventType
			entityType
			entityId
			actorType
			actorId
			metadata
			timestamp
			createdAt
			description
			actorProfile {
				... on TeamProfileType {
					__typename
					id
					fullName
				}
				... on CustomerProfileType {
					__typename
					id
					fullName
				}
			}
		}
	}
`;

export interface RecentEventsQueryResult {
	recentEvents: Event[];
}

export const EVENTS_FOR_ENTITY_QUERY = gql`
	query EventsForEntity($entityType: String!, $entityId: UUID!, $limit: Int, $offset: Int) {
		eventsForEntity(entityType: $entityType, entityId: $entityId, limit: $limit, offset: $offset) {
			id
			eventType
			entityType
			entityId
			actorType
			actorId
			metadata
			timestamp
			createdAt
			description
			actorProfile {
				... on TeamProfileType {
					__typename
					id
					fullName
				}
				... on CustomerProfileType {
					__typename
					id
					fullName
				}
			}
		}
	}
`;

export interface EventsForEntityQueryResult {
	eventsForEntity: Event[];
}

export const EVENTS_BY_ACTOR_QUERY = gql`
	query EventsByActor($actorType: String!, $actorId: UUID!, $limit: Int, $offset: Int) {
		eventsByActor(actorType: $actorType, actorId: $actorId, limit: $limit, offset: $offset) {
			id
			eventType
			entityType
			entityId
			actorType
			actorId
			metadata
			timestamp
			createdAt
			description
			actorProfile {
				... on TeamProfileType {
					__typename
					id
					fullName
				}
				... on CustomerProfileType {
					__typename
					id
					fullName
				}
			}
		}
	}
`;

export interface EventsByActorQueryResult {
	eventsByActor: Event[];
}
