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

// ==================== PROJECT MUTATIONS ====================

export const CREATE_PROJECT = gql`
	mutation CreateProject($input: CreateProjectInput!) {
		createProject(input: $input) {
			id
			customerId
			name
			date
			status
			labor
			amount
			notes
			calendarEventId
			waveServiceId
			accountAddressId
			streetAddress
			city
			state
			zipCode
		}
	}
`;

export const UPDATE_PROJECT = gql`
	mutation UpdateProject($id: UUID!, $input: UpdateProjectInput!) {
		updateProject(id: $id, input: $input) {
			id
			customerId
			name
			date
			status
			labor
			amount
			notes
			calendarEventId
			waveServiceId
			accountAddressId
			streetAddress
			city
			state
			zipCode
		}
	}
`;

export const DELETE_PROJECT = gql`
	mutation DeleteProject($id: UUID!) {
		deleteProject(id: $id)
	}
`;

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

export const ASSIGN_PROJECT_TEAM_MEMBER = gql`
	mutation AssignProjectTeamMember($projectId: UUID!, $teamProfileId: UUID!) {
		assignProjectTeamMember(projectId: $projectId, teamProfileId: $teamProfileId) {
			id
			projectId
			teamProfileId
			teamProfile {
				id
				fullName
				role
			}
		}
	}
`;

export const REMOVE_PROJECT_TEAM_MEMBER = gql`
	mutation RemoveProjectTeamMember($id: UUID!) {
		removeProjectTeamMember(id: $id)
	}
`;

// ==================== PROJECT SCOPE MUTATIONS ====================

export const CREATE_PROJECT_SCOPE = gql`
	mutation CreateProjectScope($projectId: UUID!, $input: CreateProjectScopeInput!) {
		createProjectScope(projectId: $projectId, input: $input) {
			id
			name
			description
			isActive
			categories {
				id
				name
				order
				tasks {
					id
					scopeDescription
					checklistDescription
					sessionDescription
					frequency
					order
					estimatedMinutes
				}
			}
		}
	}
`;

export const UPDATE_PROJECT_SCOPE = gql`
	mutation UpdateProjectScope($id: UUID!, $input: UpdateProjectScopeInput!) {
		updateProjectScope(id: $id, input: $input) {
			id
			name
			description
			isActive
		}
	}
`;

export const DELETE_PROJECT_SCOPE = gql`
	mutation DeleteProjectScope($id: UUID!) {
		deleteProjectScope(id: $id)
	}
`;

// ==================== PROJECT SCOPE CATEGORY MUTATIONS ====================

export const CREATE_PROJECT_SCOPE_CATEGORY = gql`
	mutation CreateProjectScopeCategory($scopeId: UUID!, $input: CreateProjectCategoryInput!) {
		createProjectScopeCategory(scopeId: $scopeId, input: $input) {
			id
			name
			order
		}
	}
`;

export const UPDATE_PROJECT_SCOPE_CATEGORY = gql`
	mutation UpdateProjectScopeCategory($id: UUID!, $input: UpdateProjectCategoryInput!) {
		updateProjectScopeCategory(id: $id, input: $input) {
			id
			name
			order
		}
	}
`;

export const DELETE_PROJECT_SCOPE_CATEGORY = gql`
	mutation DeleteProjectScopeCategory($id: UUID!) {
		deleteProjectScopeCategory(id: $id)
	}
`;

// ==================== PROJECT SCOPE TASK MUTATIONS ====================

export const CREATE_PROJECT_SCOPE_TASK = gql`
	mutation CreateProjectScopeTask($categoryId: UUID!, $input: CreateScopeTaskInput!) {
		createProjectScopeTask(categoryId: $categoryId, input: $input) {
			id
			scopeDescription
			checklistDescription
			sessionDescription
			frequency
			order
			estimatedMinutes
		}
	}
`;

export const UPDATE_PROJECT_SCOPE_TASK = gql`
	mutation UpdateProjectScopeTask($id: UUID!, $input: UpdateScopeTaskInput!) {
		updateProjectScopeTask(id: $id, input: $input) {
			id
			scopeDescription
			checklistDescription
			sessionDescription
			frequency
			order
			estimatedMinutes
		}
	}
`;

export const DELETE_PROJECT_SCOPE_TASK = gql`
	mutation DeleteProjectScopeTask($id: UUID!) {
		deleteProjectScopeTask(id: $id)
	}
`;

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

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

export interface CreateProjectInput {
	customerId: string;
	name: string;
	date: string;
	status?: WorkStatus;
	accountAddressId?: string;
	streetAddress?: string;
	city?: string;
	state?: string;
	zipCode?: string;
}

export interface UpdateProjectInput {
	name?: string;
	date?: string;
	status?: WorkStatus;
	labor?: number;
	amount?: number;
	waveServiceId?: string;
	notes?: string;
	calendarEventId?: string;
	accountAddressId?: string;
	streetAddress?: string;
	city?: string;
	state?: string;
	zipCode?: string;
}

export interface CreateProjectScopeInput {
	name: string;
	description?: string;
	categories?: CreateProjectCategoryInput[];
}

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

export interface CreateProjectCategoryInput {
	name: string;
	order?: number;
	tasks?: CreateScopeTaskInput[];
}

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

export interface CreateScopeTaskInput {
	scopeDescription: string;
	checklistDescription?: string;
	sessionDescription?: string;
	frequency?: 'DAILY' | 'WEEKLY' | 'MONTHLY' | 'QUARTERLY' | 'TRIANNUAL' | 'ANNUAL' | 'AS_NEEDED';
	order?: number;
	estimatedMinutes?: number;
}

export interface UpdateScopeTaskInput {
	scopeDescription?: string;
	checklistDescription?: string;
	sessionDescription?: string;
	frequency?: 'DAILY' | 'WEEKLY' | 'MONTHLY' | 'QUARTERLY' | 'TRIANNUAL' | 'ANNUAL' | 'AS_NEEDED';
	order?: number;
	estimatedMinutes?: number;
}
