import { colors } from '../theme/colors';

export type SaleStatus = 'PENDING' | 'PAID' | 'CANCELLED' | 'REFUNDED';

export interface Sale {
  id: string;
  trainerId: string;
  clientId: string;
  packageId?: string;
  serviceId?: string;
  amount: number;
  description?: string;
  status: SaleStatus;
  paidAt?: string;
  createdAt: string;
  trainer: {
    id: string;
    firstName: string;
    lastName: string;
  };
  client: {
    id: string;
    firstName: string;
    lastName: string;
    phone: string;
  };
  service?: {
    id: string;
    name: string;
    price: number;
  };
  package?: {
    id: string;
    name: string;
    price: number;
  };
}

export interface CreateSaleDto {
  clientId: string;
  serviceId?: string;
  packageId?: string;
  amount: number;
  description?: string;
}

export interface UpdateSaleDto {
  amount?: number;
  description?: string;
  serviceId?: string;
  packageId?: string;
}

export interface FindSalesParams {
  cursor?: string;
  limit?: number;
  trainerId?: string;
  clientId?: string;
  status?: SaleStatus;
  dateFrom?: string;
  dateTo?: string;
}

export interface DebtsSummary {
  totalAmount: number;
  count: number;
}

export const STATUS_LABELS: Record<SaleStatus, string> = {
  PENDING: 'Ожидает',
  PAID: 'Оплачено',
  CANCELLED: 'Отменено',
  REFUNDED: 'Возврат',
};

export function getStatusColor(status: SaleStatus): string {
  const map: Record<SaleStatus, string> = {
    PENDING: colors.warning,
    PAID: colors.success,
    CANCELLED: colors.error,
    REFUNDED: colors.textSecondary,
  };
  return map[status];
}
