import { QuickBooksClient } from '../clients/quickbooks.js';

export function getTools(client: QuickBooksClient) {
  return [
    {
      name: 'qbo_run_profit_loss',
      description: 'Run a Profit & Loss (P&L) report',
      inputSchema: {
        type: 'object',
        properties: {
          startDate: {
            type: 'string',
            description: 'Start date (YYYY-MM-DD)',
          },
          endDate: {
            type: 'string',
            description: 'End date (YYYY-MM-DD)',
          },
          accountingMethod: {
            type: 'string',
            description: 'Accounting method: Accrual or Cash (default: Accrual)',
          },
          summarizeColumnBy: {
            type: 'string',
            description: 'Summarize by: Total, Month, Quarter, Year, etc.',
          },
        },
        required: ['startDate', 'endDate'],
      },
      handler: async (args: any) => {
        const params: Record<string, string> = {
          start_date: args.startDate,
          end_date: args.endDate,
        };
        
        if (args.accountingMethod) params.accounting_method = args.accountingMethod;
        if (args.summarizeColumnBy) params.summarize_column_by = args.summarizeColumnBy;
        
        return await client.getReport('ProfitAndLoss', params);
      },
    },
    {
      name: 'qbo_run_balance_sheet',
      description: 'Run a Balance Sheet report',
      inputSchema: {
        type: 'object',
        properties: {
          asOfDate: {
            type: 'string',
            description: 'As of date (YYYY-MM-DD)',
          },
          accountingMethod: {
            type: 'string',
            description: 'Accounting method: Accrual or Cash (default: Accrual)',
          },
        },
        required: ['asOfDate'],
      },
      handler: async (args: any) => {
        const params: Record<string, string> = {
          date_macro: 'custom',
          end_date: args.asOfDate,
        };
        
        if (args.accountingMethod) params.accounting_method = args.accountingMethod;
        
        return await client.getReport('BalanceSheet', params);
      },
    },
    {
      name: 'qbo_run_cash_flow',
      description: 'Run a Statement of Cash Flows report',
      inputSchema: {
        type: 'object',
        properties: {
          startDate: {
            type: 'string',
            description: 'Start date (YYYY-MM-DD)',
          },
          endDate: {
            type: 'string',
            description: 'End date (YYYY-MM-DD)',
          },
        },
        required: ['startDate', 'endDate'],
      },
      handler: async (args: any) => {
        const params: Record<string, string> = {
          start_date: args.startDate,
          end_date: args.endDate,
        };
        
        return await client.getReport('CashFlow', params);
      },
    },
    {
      name: 'qbo_run_ar_aging',
      description: 'Run an Accounts Receivable (AR) Aging Summary report',
      inputSchema: {
        type: 'object',
        properties: {
          asOfDate: {
            type: 'string',
            description: 'As of date (YYYY-MM-DD)',
          },
          agingMethod: {
            type: 'string',
            description: 'Aging method: Current or Report_Date (default: Report_Date)',
          },
          numPeriods: {
            type: 'number',
            description: 'Number of aging periods (default: 4)',
          },
        },
        required: ['asOfDate'],
      },
      handler: async (args: any) => {
        const params: Record<string, string> = {
          report_date: args.asOfDate,
        };
        
        if (args.agingMethod) params.aging_method = args.agingMethod;
        if (args.numPeriods) params.num_periods = args.numPeriods.toString();
        
        return await client.getReport('AgedReceivables', params);
      },
    },
    {
      name: 'qbo_run_ap_aging',
      description: 'Run an Accounts Payable (AP) Aging Summary report',
      inputSchema: {
        type: 'object',
        properties: {
          asOfDate: {
            type: 'string',
            description: 'As of date (YYYY-MM-DD)',
          },
          agingMethod: {
            type: 'string',
            description: 'Aging method: Current or Report_Date (default: Report_Date)',
          },
          numPeriods: {
            type: 'number',
            description: 'Number of aging periods (default: 4)',
          },
        },
        required: ['asOfDate'],
      },
      handler: async (args: any) => {
        const params: Record<string, string> = {
          report_date: args.asOfDate,
        };
        
        if (args.agingMethod) params.aging_method = args.agingMethod;
        if (args.numPeriods) params.num_periods = args.numPeriods.toString();
        
        return await client.getReport('AgedPayables', params);
      },
    },
    {
      name: 'qbo_run_trial_balance',
      description: 'Run a Trial Balance report',
      inputSchema: {
        type: 'object',
        properties: {
          startDate: {
            type: 'string',
            description: 'Start date (YYYY-MM-DD)',
          },
          endDate: {
            type: 'string',
            description: 'End date (YYYY-MM-DD)',
          },
          accountingMethod: {
            type: 'string',
            description: 'Accounting method: Accrual or Cash (default: Accrual)',
          },
        },
        required: ['startDate', 'endDate'],
      },
      handler: async (args: any) => {
        const params: Record<string, string> = {
          start_date: args.startDate,
          end_date: args.endDate,
        };
        
        if (args.accountingMethod) params.accounting_method = args.accountingMethod;
        
        return await client.getReport('TrialBalance', params);
      },
    },
    {
      name: 'qbo_run_general_ledger',
      description: 'Run a General Ledger report',
      inputSchema: {
        type: 'object',
        properties: {
          startDate: {
            type: 'string',
            description: 'Start date (YYYY-MM-DD)',
          },
          endDate: {
            type: 'string',
            description: 'End date (YYYY-MM-DD)',
          },
          accountId: {
            type: 'string',
            description: 'Filter by specific account ID (optional)',
          },
          accountingMethod: {
            type: 'string',
            description: 'Accounting method: Accrual or Cash (default: Accrual)',
          },
        },
        required: ['startDate', 'endDate'],
      },
      handler: async (args: any) => {
        const params: Record<string, string> = {
          start_date: args.startDate,
          end_date: args.endDate,
        };
        
        if (args.accountId) params.account = args.accountId;
        if (args.accountingMethod) params.accounting_method = args.accountingMethod;
        
        return await client.getReport('GeneralLedger', params);
      },
    },
  ];
}
