export interface DateRange {
  from?: string; // ISO 8601
  to?: string; // ISO 8601
}

export interface PaymentMethodsFilters {
  user_id?: number;
  date_range?: DateRange;
  payment_type?: string;
  status?: 'pending' | 'paid' | 'failed' | 'refunded' | 'cancelled';
  group_by_user?: boolean;
  limit: number;
  offset: number;
}

export interface PaymentMethod {
  user_id: number;
  customer_name: string;
  customer_phone: string;
  payment_type: string;
  successful_count: number;
  failed_count: number;
  total_attempts: number;
  total_amount: number; // ریال
  success_rate: number; // درصد (0-100)
  first_used_at: string; // ISO 8601
  last_used_at: string; // ISO 8601
}

export interface PaymentTypeSummary {
  count: number;
  success_count: number;
  failed_count: number;
  total_amount: number; // ریال
  percentage: number;
  success_rate: number; // درصد
}

export interface PaymentMethodsSummary {
  total_transactions: number;
  successful_transactions: number;
  failed_transactions: number;
  total_amount: number; // ریال
  by_payment_type: Record<string, PaymentTypeSummary>;
  overall_success_rate: number; // درصد
}

export interface PaymentMethodsResponse {
  payment_methods: PaymentMethod[];
  summary: PaymentMethodsSummary;
  total: number;
  has_more: boolean;
  limit: number;
  offset: number;
}

export interface PaymentTransactionsFilters {
  user_id?: number;
  phone_number?: string;
  order_id?: number;
  transaction_id?: string;
  reference_number?: string;
  status?: 'pending' | 'paid' | 'failed' | 'refunded' | 'cancelled';
  payment_type?: string;
  min_amount?: number;
  max_amount?: number;
  from_date?: string; // RFC3339
  to_date?: string; // RFC3339
  group_by_status?: boolean;
  group_by_type?: boolean;
  sort_by?: 'amount' | 'date' | 'status';
  sort_order?: 'asc' | 'desc';
  limit: number;
  offset: number;
}

export interface PaymentTransaction {
  payment_id: number;
  transaction_id: string;
  reference_number: string;
  user_id: number;
  customer_name: string;
  customer_phone: string;
  invoice_id: number;
  order_number: string;
  amount: number; // ریال
  payment_type: string;
  status: string;
  step: string;
  created_at: string; // ISO 8601
  updated_at: string; // ISO 8601
}

export interface PaymentTransactionsSummary {
  total_transactions: number;
  successful_count: number;
  failed_count: number;
  pending_count: number;
  cancelled_count: number;
  refunded_count: number;
  total_success_amount: number; // ریال
  total_failed_amount: number; // ریال
  success_rate: number; // درصد
  average_transaction_amount: number; // ریال
}

export interface PaymentTransactionsResponse {
  transactions: PaymentTransaction[];
  summary: PaymentTransactionsSummary;
  total: number;
  has_more: boolean;
  limit: number;
  offset: number;
}
