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

export const ACCOUNTS_QUERY = gql`
	query Accounts($customerId: UUID, $filter: AccountFilter) {
		accounts(customerId: $customerId, filter: $filter) {
			id
			customerId
			name
			status
			isActive
			customer {
				id
				name
			}
			addresses {
				id
				city
				state
				isPrimary
			}
			revenues {
				waveServiceId
				isActive
			}
		}
	}
`;

export type EntityStatus = 'ACTIVE' | 'INACTIVE' | 'PENDING';

export interface AccountFilterInput {
	name?: string;
	status?: EntityStatus;
	isActive?: boolean;
}

export interface AccountListAddress {
	id: string;
	city: string;
	state: string;
	isPrimary: boolean;
}

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

export interface AccountListRevenue {
	waveServiceId: string | null;
	isActive: boolean;
}

export interface AccountListItem {
	id: string;
	customerId: string;
	name: string;
	status: EntityStatus;
	isActive: boolean;
	customer: AccountListCustomer | null;
	addresses: AccountListAddress[];
	revenues: AccountListRevenue[];
}

export interface AccountsQueryResult {
	accounts: AccountListItem[];
}

// ==================== ACCOUNTS WITH SCHEDULES QUERY ====================

export const ACCOUNTS_WITH_SCHEDULES_QUERY = gql`
	query AccountsWithSchedules {
		accounts(filter: { status: ACTIVE }) {
			id
			name
			status
			customer {
				id
				name
			}
			addresses {
				id
				name
				city
				state
				isPrimary
				isActive
				schedules {
					id
					name
					monday
					tuesday
					wednesday
					thursday
					friday
					saturday
					sunday
					weekendService
					startDate
					endDate
				}
			}
		}
	}
`;

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

export interface AddressForGeneration {
	id: string;
	name: string | null;
	city: string;
	state: string;
	isPrimary: boolean;
	isActive: boolean;
	schedules: ScheduleForGeneration[];
}

export interface AccountForGeneration {
	id: string;
	name: string;
	status: EntityStatus;
	customer: AccountListCustomer | null;
	addresses: AddressForGeneration[];
}

export interface AccountsWithSchedulesQueryResult {
	accounts: AccountForGeneration[];
}
