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

export const ACCOUNT_QUERY = gql`
	query Account($id: UUID!) {
		account(id: $id) {
			id
			customerId
			name
			status
			startDate
			endDate
			isActive
			customer {
				id
				name
			}
			contacts {
				id
				firstName
				lastName
				email
				phone
				isActive
				isPrimary
				notes
			}
			addresses {
				id
				accountId
				name
				streetAddress
				city
				state
				zipCode
				isActive
				isPrimary
				notes
				labor {
					id
					amount
					startDate
					endDate
					isActive
				}
				schedules {
					id
					name
					monday
					tuesday
					wednesday
					thursday
					friday
					saturday
					sunday
					weekendService
					scheduleException
					startDate
					endDate
					isActive
				}
				scopes {
					id
					name
					description
					isActive
					areas {
						id
						name
						order
						tasks {
							id
							scopeDescription
							checklistDescription
							sessionDescription
							frequency
							order
							estimatedMinutes
						}
					}
				}
			}
			revenues {
				id
				amount
				startDate
				endDate
				waveServiceId
				waveProductName
				isActive
			}
		}
	}
`;

export interface AccountContact {
	id: string;
	firstName: string;
	lastName: string;
	email: string | null;
	phone: string | null;
	isActive: boolean;
	isPrimary: boolean;
	notes: string | null;
}

export interface AddressLabor {
	id: string;
	amount: string;
	startDate: string;
	endDate: string | null;
	isActive: boolean;
}

export interface AddressSchedule {
	id: string;
	name: string | null;
	monday: boolean;
	tuesday: boolean;
	wednesday: boolean;
	thursday: boolean;
	friday: boolean;
	saturday: boolean;
	sunday: boolean;
	weekendService: boolean;
	scheduleException: string | null;
	startDate: string | null;
	endDate: string | null;
	isActive: boolean;
}

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

export interface ScopeArea {
	id: string;
	name: string;
	order: number;
	tasks: ScopeTask[];
}

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

export interface AccountAddress {
	id: string;
	accountId: string;
	name: string | null;
	streetAddress: string;
	city: string;
	state: string;
	zipCode: string;
	isActive: boolean;
	isPrimary: boolean;
	notes: string | null;
	labor: AddressLabor[];
	schedules: AddressSchedule[];
	scopes: AddressScope[];
}

export interface AccountCustomer {
	id: string;
	name: string;
}

export interface AccountRevenue {
	id: string;
	amount: string; // Decimal comes as string from GraphQL
	startDate: string;
	endDate: string | null;
	waveServiceId: string | null;
	waveProductName: string | null;
	isActive: boolean;
}

export interface Account {
	id: string;
	customerId: string;
	name: string;
	status: string;
	startDate: string | null;
	endDate: string | null;
	isActive: boolean;
	customer: AccountCustomer | null;
	contacts: AccountContact[];
	addresses: AccountAddress[];
	revenues: AccountRevenue[];
}

export interface AccountQueryResult {
	account: Account | null;
}
