/**
 * Mobile App Types
 */

// ===== Auth Types =====

export interface User {
  id: string;
  email: string;
  fullName: string;
  tenantId: string;
  companyId?: string;
  role: string;
  avatar?: string;
}

export interface AuthState {
  user: User | null;
  token: string | null;
  refreshToken: string | null;
  isAuthenticated: boolean;
  isLoading: boolean;
}

export interface LoginCredentials {
  email: string;
  password: string;
  tenantId?: string;
}

export interface AuthResponse {
  user: User;
  token: string;
  refreshToken: string;
  expiresIn: number;
}

// ===== API Types =====

export interface ApiResponse<T> {
  data: T;
  message?: string;
  success: boolean;
}

export interface PaginatedResponse<T> {
  data: T[];
  total: number;
  page: number;
  limit: number;
  totalPages: number;
}

export interface ApiError {
  message: string;
  code?: string;
  statusCode: number;
  errors?: Record<string, string[]>;
}

// ===== Partner Types =====

export interface Partner {
  id: string;
  name: string;
  email?: string;
  phone?: string;
  isCustomer: boolean;
  isSupplier: boolean;
  active: boolean;
  creditLimit?: number;
  taxId?: string;
}

// ===== Product Types =====

export interface Product {
  id: string;
  code: string;
  name: string;
  productType: 'product' | 'service' | 'consumable';
  unitPrice: number;
  costPrice: number;
  isActive: boolean;
  categoryId?: string;
  categoryName?: string;
}

// ===== Financial Types =====

export interface Invoice {
  id: string;
  number: string;
  partnerId: string;
  partnerName?: string;
  invoiceType: 'out_invoice' | 'out_refund' | 'in_invoice' | 'in_refund';
  state: 'draft' | 'posted' | 'paid' | 'cancelled';
  invoiceDate: string;
  dueDate?: string;
  amountTotal: number;
  amountDue: number;
  currency: string;
}

// ===== Navigation Types =====

export type RootStackParamList = {
  '(auth)': undefined;
  '(tabs)': undefined;
  modal: undefined;
};

export type AuthStackParamList = {
  login: undefined;
  'forgot-password': undefined;
  'tenant-select': undefined;
};

export type TabParamList = {
  index: undefined;
  partners: undefined;
  products: undefined;
  invoices: undefined;
  settings: undefined;
};

// ===== Theme Types =====

export type ThemeMode = 'light' | 'dark' | 'system';

export interface ThemeColors {
  primary: string;
  secondary: string;
  background: string;
  surface: string;
  text: string;
  textSecondary: string;
  border: string;
  error: string;
  success: string;
  warning: string;
}

// ===== Barcode Types =====

export interface ScannedBarcode {
  type: string;
  data: string;
  timestamp: number;
  cornerPoints?: { x: number; y: number }[];
}

export interface ProductBarcode {
  code: string;
  type: 'ean13' | 'ean8' | 'upc_a' | 'upc_e' | 'other';
  isValid: boolean;
}

export interface ParsedQRData {
  type: 'url' | 'product' | 'invoice' | 'partner' | 'text' | 'json';
  data: Record<string, any>;
  raw: string;
}
