// GraphQL API types

import type {
  Company,
  Account,
  Transaction,
  BankAccount,
  BankTransaction,
  VATReport,
  Employee,
  PayrollEntry,
  PaginatedResponse,
  DateRange,
} from './accounting';

// Query response types
export interface CompaniesQueryResponse {
  companies: Company[];
}

export interface TransactionsQueryResponse {
  transactions: PaginatedResponse<Transaction>;
}

export interface AccountsQueryResponse {
  accounts: Account[];
}

export interface BankAccountsQueryResponse {
  bankAccounts: BankAccount[];
}

export interface BankTransactionsQueryResponse {
  bankTransactions: BankTransaction[];
}

export interface VATReportQueryResponse {
  vatReport: VATReport;
}

export interface EmployeesQueryResponse {
  employees: Employee[];
}

export interface PayrollQueryResponse {
  payrollEntries: PayrollEntry[];
}

// Query variables
export interface TransactionsQueryVariables {
  companyId: string;
  first?: number;
  after?: string;
  filter?: TransactionFilter;
  sort?: TransactionSort;
}

export interface TransactionFilter {
  dateFrom?: string;
  dateTo?: string;
  accountId?: string;
  minAmount?: number;
  maxAmount?: number;
  description?: string;
  isReconciled?: boolean;
}

export interface TransactionSort {
  field: 'date' | 'transactionNumber' | 'description' | 'amount';
  direction: 'ASC' | 'DESC';
}

export interface BankTransactionsQueryVariables {
  companyId: string;
  bankAccountId: string;
  period: DateRange;
  isReconciled?: boolean;
}

export interface VATReportQueryVariables {
  companyId: string;
  period: DateRange;
}

// Mutation inputs
export interface CreateTransactionInput {
  companyId: string;
  date: string;
  description: string;
  lines: CreateTransactionLineInput[];
  attachmentIds?: string[];
}

export interface CreateTransactionLineInput {
  accountId: string;
  description?: string;
  debit: number;
  credit: number;
  vatCode?: string;
}

export interface MatchBankTransactionInput {
  bankTransactionId: string;
  ledgerTransactionId?: string;
  createTransaction?: CreateTransactionInput;
}

export interface VoidTransactionInput {
  transactionId: string;
  reason: string;
}

// Mutation response types
export interface CreateTransactionResponse {
  createTransaction: Transaction;
}

export interface MatchBankTransactionResponse {
  matchBankTransaction: {
    success: boolean;
    bankTransaction: BankTransaction;
    matchedTransaction?: Transaction;
  };
}

// Dashboard/Analytics types
export interface DashboardMetrics {
  cashPosition: number;
  accountsReceivable: number;
  accountsPayable: number;
  monthlyRevenue: number;
  monthlyExpenses: number;
  vatLiability: number;
  unreconciledTransactions: number;
}

export interface CashFlowData {
  date: string;
  inflow: number;
  outflow: number;
  balance: number;
}

export interface AccountBalanceData {
  accountId: string;
  accountName: string;
  accountNumber: string;
  balance: number;
  type: string;
}
