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

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

export const CREATE_PROJECT_SCOPE_TEMPLATE = gql`
	mutation CreateProjectScopeTemplate($input: CreateProjectScopeTemplateInput!) {
		createProjectScopeTemplate(input: $input) {
			id
			name
			description
			isActive
		}
	}
`;

export const UPDATE_PROJECT_SCOPE_TEMPLATE = gql`
	mutation UpdateProjectScopeTemplate($id: UUID!, $input: UpdateProjectScopeTemplateInput!) {
		updateProjectScopeTemplate(id: $id, input: $input) {
			id
			name
			description
			isActive
		}
	}
`;

export const DELETE_PROJECT_SCOPE_TEMPLATE = gql`
	mutation DeleteProjectScopeTemplate($id: UUID!) {
		deleteProjectScopeTemplate(id: $id)
	}
`;

export const IMPORT_PROJECT_SCOPE_TEMPLATE = gql`
	mutation ImportProjectScopeTemplate($input: ImportProjectScopeTemplateInput!) {
		importProjectScopeTemplate(input: $input) {
			id
			name
			description
			isActive
		}
	}
`;

// ==================== CATEGORY MUTATIONS ====================

export const CREATE_PROJECT_SCOPE_TEMPLATE_CATEGORY = gql`
	mutation CreateProjectScopeTemplateCategory(
		$templateId: UUID!
		$input: CreateProjectScopeTemplateCategoryInput!
	) {
		createProjectScopeTemplateCategory(templateId: $templateId, input: $input) {
			id
			templateId
			name
			order
		}
	}
`;

export const UPDATE_PROJECT_SCOPE_TEMPLATE_CATEGORY = gql`
	mutation UpdateProjectScopeTemplateCategory(
		$id: UUID!
		$input: UpdateProjectScopeTemplateCategoryInput!
	) {
		updateProjectScopeTemplateCategory(id: $id, input: $input) {
			id
			templateId
			name
			order
		}
	}
`;

export const DELETE_PROJECT_SCOPE_TEMPLATE_CATEGORY = gql`
	mutation DeleteProjectScopeTemplateCategory($id: UUID!) {
		deleteProjectScopeTemplateCategory(id: $id)
	}
`;

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

export const CREATE_PROJECT_SCOPE_TEMPLATE_TASK = gql`
	mutation CreateProjectScopeTemplateTask(
		$categoryId: UUID!
		$input: CreateProjectScopeTemplateTaskInput!
	) {
		createProjectScopeTemplateTask(categoryId: $categoryId, input: $input) {
			id
			categoryId
			scopeDescription
			checklistDescription
			sessionDescription
			order
			estimatedMinutes
		}
	}
`;

export const UPDATE_PROJECT_SCOPE_TEMPLATE_TASK = gql`
	mutation UpdateProjectScopeTemplateTask(
		$id: UUID!
		$input: UpdateProjectScopeTemplateTaskInput!
	) {
		updateProjectScopeTemplateTask(id: $id, input: $input) {
			id
			categoryId
			scopeDescription
			checklistDescription
			sessionDescription
			order
			estimatedMinutes
		}
	}
`;

export const DELETE_PROJECT_SCOPE_TEMPLATE_TASK = gql`
	mutation DeleteProjectScopeTemplateTask($id: UUID!) {
		deleteProjectScopeTemplateTask(id: $id)
	}
`;

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

export const CREATE_PROJECT_SCOPE_FROM_TEMPLATE = gql`
	mutation CreateProjectScopeFromTemplate($templateId: UUID!, $projectId: UUID!) {
		createProjectScopeFromTemplate(templateId: $templateId, projectId: $projectId)
	}
`;

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

export interface CreateProjectScopeTemplateInput {
	name: string;
	description?: string;
	categories?: CreateProjectScopeTemplateCategoryInput[];
}

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

export interface CreateProjectScopeTemplateCategoryInput {
	name: string;
	order?: number;
	tasks?: CreateProjectScopeTemplateTaskInput[];
}

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

export interface CreateProjectScopeTemplateTaskInput {
	scopeDescription: string;
	checklistDescription?: string;
	sessionDescription?: string;
	order?: number;
	estimatedMinutes?: number;
}

export interface UpdateProjectScopeTemplateTaskInput {
	scopeDescription?: string;
	checklistDescription?: string;
	sessionDescription?: string;
	order?: number;
	estimatedMinutes?: number;
}

export interface ImportProjectScopeTemplateInput {
	name: string;
	description?: string;
	categories: ImportProjectScopeTemplateCategoryInput[];
	replace?: boolean;
}

export interface ImportProjectScopeTemplateCategoryInput {
	name: string;
	order: number;
	tasks: ImportProjectScopeTemplateTaskInput[];
}

export interface ImportProjectScopeTemplateTaskInput {
	scopeDescription: string;
	checklistDescription?: string;
	sessionDescription?: string;
	order: number;
	estimatedMinutes?: number;
}
