import type { ServicesForTeam$input, ProjectsForTeam$input } from '$houdini';
import { fromGlobalId } from '$lib/utils/relay';
import { getMonthDateRange } from '$lib/utils/date';

export interface TeamDataParams {
	teamProfileId: string; // Relay global ID - will be decoded to UUID
	month: string; // YYYY-MM format
}

export interface StatusVariables<T> {
	scheduled: T;
	inProgress: T;
	completed: T;
}

/**
 * Build GraphQL variables for all service status categories
 */
export function buildAllServiceVariables(
	params: TeamDataParams
): StatusVariables<ServicesForTeam$input> {
	const { start, end } = getMonthDateRange(params.month);
	const baseDateFilter = { gte: start, lte: end };
	const teamProfileId = fromGlobalId(params.teamProfileId);

	return {
		scheduled: {
			teamProfileId,
			filters: {
				date: baseDateFilter,
				status: { exact: 'SCHEDULED' }
			},
			ordering: 'ASC',
			first: 20
		},
		inProgress: {
			teamProfileId,
			filters: {
				date: baseDateFilter,
				status: { exact: 'IN_PROGRESS' }
			},
			ordering: 'DESC',
			first: 50 // Load all - typically small number
		},
		completed: {
			teamProfileId,
			filters: {
				date: baseDateFilter,
				status: { exact: 'COMPLETED' }
			},
			ordering: 'DESC',
			first: 20
		}
	};
}

/**
 * Build GraphQL variables for all project status categories
 */
export function buildAllProjectVariables(
	params: TeamDataParams
): StatusVariables<ProjectsForTeam$input> {
	const { start, end } = getMonthDateRange(params.month);
	const baseDateFilter = { gte: start, lte: end };
	const teamProfileId = fromGlobalId(params.teamProfileId);

	return {
		scheduled: {
			teamProfileId,
			filters: {
				date: baseDateFilter,
				status: { exact: 'SCHEDULED' }
			},
			ordering: 'ASC',
			first: 20
		},
		inProgress: {
			teamProfileId,
			filters: {
				date: baseDateFilter,
				status: { exact: 'IN_PROGRESS' }
			},
			ordering: 'DESC',
			first: 50 // Load all - typically small number
		},
		completed: {
			teamProfileId,
			filters: {
				date: baseDateFilter,
				status: { exact: 'COMPLETED' }
			},
			ordering: 'DESC',
			first: 20
		}
	};
}
