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

export const CREATE_INVOICE = gql`
	mutation CreateInvoice($input: CreateInvoiceInput!) {
		createInvoice(input: $input) {
			id
			customerId
			startDate
			endDate
			status
		}
	}
`;

export const UPDATE_INVOICE = gql`
	mutation UpdateInvoice($id: UUID!, $input: UpdateInvoiceInput!) {
		updateInvoice(id: $id, input: $input) {
			id
			customerId
			startDate
			endDate
			status
			datePaid
			waveInvoiceId
		}
	}
`;

export const DELETE_INVOICE = gql`
	mutation DeleteInvoice($id: UUID!) {
		deleteInvoice(id: $id)
	}
`;

export const ADD_REVENUE_TO_INVOICE = gql`
	mutation AddRevenueToInvoice($invoiceId: UUID!, $revenueId: UUID!) {
		addRevenueToInvoice(invoiceId: $invoiceId, revenueId: $revenueId) {
			id
			invoiceId
			revenueId
			amount
		}
	}
`;

export const ADD_PROJECT_TO_INVOICE = gql`
	mutation AddProjectToInvoice($invoiceId: UUID!, $projectId: UUID!) {
		addProjectToInvoice(invoiceId: $invoiceId, projectId: $projectId) {
			id
			invoiceId
			projectId
			amount
		}
	}
`;

export const REMOVE_REVENUE_FROM_INVOICE = gql`
	mutation RemoveRevenueFromInvoice($id: UUID!) {
		removeRevenueFromInvoice(id: $id)
	}
`;

export const REMOVE_PROJECT_FROM_INVOICE = gql`
	mutation RemoveProjectFromInvoice($id: UUID!) {
		removeProjectFromInvoice(id: $id)
	}
`;

export const ADD_ALL_ELIGIBLE_REVENUES = gql`
	mutation AddAllEligibleRevenuesToInvoice($invoiceId: UUID!) {
		addAllEligibleRevenuesToInvoice(invoiceId: $invoiceId)
	}
`;

export const ADD_ALL_ELIGIBLE_PROJECTS = gql`
	mutation AddAllEligibleProjectsToInvoice($invoiceId: UUID!) {
		addAllEligibleProjectsToInvoice(invoiceId: $invoiceId)
	}
`;

// Input types for mutations
export interface CreateInvoiceInput {
	customerId: string;
	startDate: string;
	endDate: string;
}

export interface UpdateInvoiceInput {
	startDate?: string;
	endDate?: string;
	status?: 'DRAFT' | 'SENT' | 'PAID' | 'OVERDUE' | 'CANCELLED';
	datePaid?: string;
	waveInvoiceId?: string;
}
