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

// ==================== SERVICE MUTATIONS ====================

export const CREATE_SERVICE = gql`
	mutation CreateService($input: CreateServiceInput!) {
		createService(input: $input) {
			id
			accountId
			accountAddressId
			date
			status
			notes
			calendarEventId
		}
	}
`;

export const UPDATE_SERVICE = gql`
	mutation UpdateService($id: UUID!, $input: UpdateServiceInput!) {
		updateService(id: $id, input: $input) {
			id
			accountId
			accountAddressId
			date
			status
			notes
			calendarEventId
		}
	}
`;

export const DELETE_SERVICE = gql`
	mutation DeleteService($id: UUID!) {
		deleteService(id: $id)
	}
`;

// ==================== TEAM MEMBER ASSIGNMENT ====================

export const ASSIGN_SERVICE_TEAM_MEMBER = gql`
	mutation AssignServiceTeamMember($serviceId: UUID!, $teamProfileId: UUID!) {
		assignServiceTeamMember(serviceId: $serviceId, teamProfileId: $teamProfileId) {
			id
			serviceId
			teamProfileId
			teamProfile {
				id
				fullName
				role
			}
		}
	}
`;

export const REMOVE_SERVICE_TEAM_MEMBER = gql`
	mutation RemoveServiceTeamMember($id: UUID!) {
		removeServiceTeamMember(id: $id)
	}
`;

// ==================== INPUT TYPES ====================

export type WorkStatus = 'SCHEDULED' | 'IN_PROGRESS' | 'COMPLETED' | 'CANCELLED';

export interface CreateServiceInput {
	accountId: string;
	accountAddressId: string;
	date: string;
	status?: WorkStatus;
	notes?: string;
}

export interface UpdateServiceInput {
	date?: string;
	status?: WorkStatus;
	notes?: string;
	calendarEventId?: string;
}

// ==================== GENERATE SERVICES ====================

export const GENERATE_SERVICES_BY_MONTH = gql`
	mutation GenerateServicesByMonth($input: GenerateServicesInput!) {
		generateServicesByMonth(input: $input) {
			id
			date
			status
			notes
		}
	}
`;

export interface GenerateServicesInput {
	accountAddressId: string;
	scheduleId: string;
	month: number;
	year: number;
}

export interface GeneratedService {
	id: string;
	date: string;
	status: WorkStatus;
	notes: string | null;
}

export interface GenerateServicesByMonthResult {
	generateServicesByMonth: GeneratedService[];
}
