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

export const SERVICE_SCOPE_TEMPLATES_QUERY = gql`
	query ServiceScopeTemplates($isActive: Boolean) {
		serviceScopeTemplates(isActive: $isActive) {
			id
			name
			description
			isActive
			areaCount
			taskCount
		}
	}
`;

export const SERVICE_SCOPE_TEMPLATE_QUERY = gql`
	query ServiceScopeTemplate($id: UUID!) {
		serviceScopeTemplate(id: $id) {
			id
			name
			description
			isActive
			areas {
				id
				templateId
				name
				order
				taskCount
				tasks {
					id
					areaId
					scopeDescription
					checklistDescription
					sessionDescription
					frequency
					order
					estimatedMinutes
				}
			}
		}
	}
`;

export type TaskFrequency =
	| 'DAILY'
	| 'WEEKLY'
	| 'MONTHLY'
	| 'QUARTERLY'
	| 'TRIANNUAL'
	| 'ANNUAL'
	| 'AS_NEEDED';

export interface ServiceScopeTemplateListItem {
	id: string;
	name: string;
	description: string | null;
	isActive: boolean;
	areaCount: number;
	taskCount: number;
}

export interface ServiceScopeTemplateTask {
	id: string;
	areaId: string;
	scopeDescription: string;
	checklistDescription: string;
	sessionDescription: string;
	frequency: TaskFrequency;
	order: number;
	estimatedMinutes: number | null;
}

export interface ServiceScopeTemplateArea {
	id: string;
	templateId: string;
	name: string;
	order: number;
	taskCount: number;
	tasks: ServiceScopeTemplateTask[];
}

export interface ServiceScopeTemplate {
	id: string;
	name: string;
	description: string | null;
	isActive: boolean;
	areas: ServiceScopeTemplateArea[];
}

export interface ServiceScopeTemplatesQueryResult {
	serviceScopeTemplates: ServiceScopeTemplateListItem[];
}

export interface ServiceScopeTemplateQueryResult {
	serviceScopeTemplate: ServiceScopeTemplate | null;
}

export const FREQUENCY_LABELS: Record<TaskFrequency, string> = {
	DAILY: 'Daily',
	WEEKLY: 'Weekly',
	MONTHLY: 'Monthly',
	QUARTERLY: 'Quarterly',
	TRIANNUAL: 'Triannual',
	ANNUAL: 'Annual',
	AS_NEEDED: 'As Needed'
};

export const FREQUENCY_SHORT_LABELS: Record<TaskFrequency, string> = {
	DAILY: 'D',
	WEEKLY: 'W',
	MONTHLY: 'M',
	QUARTERLY: 'Q',
	TRIANNUAL: '3Y',
	ANNUAL: 'A',
	AS_NEEDED: 'PRN'
};
