import { gql } from '@apollo/client/core';
import type { TaskFrequency } from '../queries/service-scope-templates';

// ==================== TEMPLATE MUTATIONS ====================

export const CREATE_SERVICE_SCOPE_TEMPLATE = gql`
	mutation CreateServiceScopeTemplate($input: CreateServiceScopeTemplateInput!) {
		createServiceScopeTemplate(input: $input) {
			id
			name
			description
			isActive
		}
	}
`;

export const UPDATE_SERVICE_SCOPE_TEMPLATE = gql`
	mutation UpdateServiceScopeTemplate($id: UUID!, $input: UpdateServiceScopeTemplateInput!) {
		updateServiceScopeTemplate(id: $id, input: $input) {
			id
			name
			description
			isActive
		}
	}
`;

export const DELETE_SERVICE_SCOPE_TEMPLATE = gql`
	mutation DeleteServiceScopeTemplate($id: UUID!) {
		deleteServiceScopeTemplate(id: $id)
	}
`;

export const IMPORT_SERVICE_SCOPE_TEMPLATE = gql`
	mutation ImportServiceScopeTemplate($input: ImportServiceScopeTemplateInput!) {
		importServiceScopeTemplate(input: $input) {
			id
			name
			description
			isActive
		}
	}
`;

// ==================== AREA MUTATIONS ====================

export const CREATE_SERVICE_SCOPE_TEMPLATE_AREA = gql`
	mutation CreateServiceScopeTemplateArea(
		$templateId: UUID!
		$input: CreateServiceScopeTemplateAreaInput!
	) {
		createServiceScopeTemplateArea(templateId: $templateId, input: $input) {
			id
			templateId
			name
			order
		}
	}
`;

export const UPDATE_SERVICE_SCOPE_TEMPLATE_AREA = gql`
	mutation UpdateServiceScopeTemplateArea(
		$id: UUID!
		$input: UpdateServiceScopeTemplateAreaInput!
	) {
		updateServiceScopeTemplateArea(id: $id, input: $input) {
			id
			templateId
			name
			order
		}
	}
`;

export const DELETE_SERVICE_SCOPE_TEMPLATE_AREA = gql`
	mutation DeleteServiceScopeTemplateArea($id: UUID!) {
		deleteServiceScopeTemplateArea(id: $id)
	}
`;

// ==================== TASK MUTATIONS ====================

export const CREATE_SERVICE_SCOPE_TEMPLATE_TASK = gql`
	mutation CreateServiceScopeTemplateTask(
		$areaId: UUID!
		$input: CreateServiceScopeTemplateTaskInput!
	) {
		createServiceScopeTemplateTask(areaId: $areaId, input: $input) {
			id
			areaId
			scopeDescription
			checklistDescription
			sessionDescription
			frequency
			order
			estimatedMinutes
		}
	}
`;

export const UPDATE_SERVICE_SCOPE_TEMPLATE_TASK = gql`
	mutation UpdateServiceScopeTemplateTask(
		$id: UUID!
		$input: UpdateServiceScopeTemplateTaskInput!
	) {
		updateServiceScopeTemplateTask(id: $id, input: $input) {
			id
			areaId
			scopeDescription
			checklistDescription
			sessionDescription
			frequency
			order
			estimatedMinutes
		}
	}
`;

export const DELETE_SERVICE_SCOPE_TEMPLATE_TASK = gql`
	mutation DeleteServiceScopeTemplateTask($id: UUID!) {
		deleteServiceScopeTemplateTask(id: $id)
	}
`;

// ==================== INSTANTIATION MUTATIONS ====================

export const CREATE_SERVICE_SCOPE_FROM_TEMPLATE = gql`
	mutation CreateServiceScopeFromTemplate(
		$templateId: UUID!
		$accountId: UUID!
		$accountAddressId: UUID!
	) {
		createServiceScopeFromTemplate(
			templateId: $templateId
			accountId: $accountId
			accountAddressId: $accountAddressId
		)
	}
`;

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

export interface CreateServiceScopeTemplateInput {
	name: string;
	description?: string;
	areas?: CreateServiceScopeTemplateAreaInput[];
}

export interface UpdateServiceScopeTemplateInput {
	name?: string;
	description?: string;
	isActive?: boolean;
}

export interface CreateServiceScopeTemplateAreaInput {
	name: string;
	order?: number;
	tasks?: CreateServiceScopeTemplateTaskInput[];
}

export interface UpdateServiceScopeTemplateAreaInput {
	name?: string;
	order?: number;
}

export interface CreateServiceScopeTemplateTaskInput {
	scopeDescription: string;
	checklistDescription?: string;
	sessionDescription?: string;
	frequency?: TaskFrequency;
	order?: number;
	estimatedMinutes?: number;
}

export interface UpdateServiceScopeTemplateTaskInput {
	scopeDescription?: string;
	checklistDescription?: string;
	sessionDescription?: string;
	frequency?: TaskFrequency;
	order?: number;
	estimatedMinutes?: number;
}

export interface ImportServiceScopeTemplateInput {
	name: string;
	description?: string;
	areas: ImportServiceScopeTemplateAreaInput[];
	replace?: boolean;
}

export interface ImportServiceScopeTemplateAreaInput {
	name: string;
	order: number;
	tasks: ImportServiceScopeTemplateTaskInput[];
}

export interface ImportServiceScopeTemplateTaskInput {
	scopeDescription: string;
	checklistDescription?: string;
	sessionDescription?: string;
	frequency?: TaskFrequency;
	order: number;
	estimatedMinutes?: number;
}
