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

export const CREATE_CALENDAR_EVENT = gql`
	mutation CreateCalendarEvent($input: CreateCalendarEventInput!) {
		createCalendarEvent(input: $input) {
			id
			summary
			description
			location
			start {
				dateTime
				date
				timeZone
			}
			end {
				dateTime
				date
				timeZone
			}
			colorId
			htmlLink
			status
		}
	}
`;

export const UPDATE_CALENDAR_EVENT = gql`
	mutation UpdateCalendarEvent($eventId: String!, $input: UpdateCalendarEventInput!) {
		updateCalendarEvent(eventId: $eventId, input: $input) {
			id
			summary
			description
			location
			start {
				dateTime
				date
				timeZone
			}
			end {
				dateTime
				date
				timeZone
			}
			colorId
			htmlLink
			status
		}
	}
`;

export const DELETE_CALENDAR_EVENT = gql`
	mutation DeleteCalendarEvent($eventId: String!) {
		deleteCalendarEvent(eventId: $eventId)
	}
`;

export const LINK_CALENDAR_EVENT_TO_SERVICE = gql`
	mutation LinkCalendarEventToService($serviceId: UUID!, $eventId: String!) {
		linkCalendarEventToService(serviceId: $serviceId, eventId: $eventId)
	}
`;

export const UNLINK_CALENDAR_EVENT_FROM_SERVICE = gql`
	mutation UnlinkCalendarEventFromService($serviceId: UUID!) {
		unlinkCalendarEventFromService(serviceId: $serviceId)
	}
`;

export const LINK_CALENDAR_EVENT_TO_PROJECT = gql`
	mutation LinkCalendarEventToProject($projectId: UUID!, $eventId: String!) {
		linkCalendarEventToProject(projectId: $projectId, eventId: $eventId)
	}
`;

export const UNLINK_CALENDAR_EVENT_FROM_PROJECT = gql`
	mutation UnlinkCalendarEventFromProject($projectId: UUID!) {
		unlinkCalendarEventFromProject(projectId: $projectId)
	}
`;

export const CREATE_SERVICE_CALENDAR_EVENT = gql`
	mutation CreateServiceCalendarEvent($serviceId: UUID!, $input: CreateCalendarEventInput!) {
		createServiceCalendarEvent(serviceId: $serviceId, input: $input) {
			id
			summary
			description
			location
			start {
				dateTime
				date
				timeZone
			}
			end {
				dateTime
				date
				timeZone
			}
			colorId
			htmlLink
			status
		}
	}
`;

export const CREATE_PROJECT_CALENDAR_EVENT = gql`
	mutation CreateProjectCalendarEvent($projectId: UUID!, $input: CreateCalendarEventInput!) {
		createProjectCalendarEvent(projectId: $projectId, input: $input) {
			id
			summary
			description
			location
			start {
				dateTime
				date
				timeZone
			}
			end {
				dateTime
				date
				timeZone
			}
			colorId
			htmlLink
			status
		}
	}
`;

export const DELETE_SERVICE_CALENDAR_EVENT = gql`
	mutation DeleteServiceCalendarEvent($serviceId: UUID!) {
		deleteServiceCalendarEvent(serviceId: $serviceId)
	}
`;

export const DELETE_PROJECT_CALENDAR_EVENT = gql`
	mutation DeleteProjectCalendarEvent($projectId: UUID!) {
		deleteProjectCalendarEvent(projectId: $projectId)
	}
`;

// Input types
export interface EventDateTimeInput {
	dateTime?: string;
	date?: string;
	timeZone?: string;
}

export interface AttendeeInput {
	email: string;
	displayName?: string;
	optional?: boolean;
}

export interface EventReminderInput {
	method: string;
	minutes: number;
}

export interface EventRemindersInput {
	useDefault: boolean;
	overrides?: EventReminderInput[];
}

export interface CreateCalendarEventInput {
	id?: string;
	summary: string;
	description?: string;
	location?: string;
	start: EventDateTimeInput;
	end: EventDateTimeInput;
	attendees?: AttendeeInput[];
	reminders?: EventRemindersInput;
	colorId?: string;
}

export interface UpdateCalendarEventInput {
	summary?: string;
	description?: string;
	location?: string;
	start?: EventDateTimeInput;
	end?: EventDateTimeInput;
	attendees?: AttendeeInput[];
	reminders?: EventRemindersInput;
	colorId?: string;
}

export interface CreateCalendarEventResult {
	createCalendarEvent: {
		id: string;
		summary: string;
		description?: string;
		location?: string;
		htmlLink?: string;
		status?: string;
	} | null;
}
