// Mock Dealer Database - In production, this would be fetched from API
export interface DealerInfo {
  code: string;
  name: string;
  email: string;
  phone: string;
  address: string;
  city: string;
  state: string;
  region: string;
  managerName: string;
}

export const DEALER_DATABASE: Record<string, DealerInfo> = {
  'RE-MH-001': {
    code: 'RE-MH-001',
    name: 'Royal Motors Mumbai',
    email: 'dealer@royalmotorsmumbai.com',
    phone: '+91 98765 12345',
    address: 'Shop No. 12-15, Central Avenue, Andheri West',
    city: 'Mumbai',
    state: 'Maharashtra',
    region: 'West',
    managerName: 'Rahul Deshmukh'
  },
  'RE-DL-002': {
    code: 'RE-DL-002',
    name: 'Delhi Enfield Center',
    email: 'contact@delhienfield.com',
    phone: '+91 98765 23456',
    address: '45-48, Rajouri Garden, Main Market',
    city: 'New Delhi',
    state: 'Delhi',
    region: 'North',
    managerName: 'Vikram Singh'
  },
  'RE-BLR-003': {
    code: 'RE-BLR-003',
    name: 'Bangalore Royal Bikes',
    email: 'info@bangaloreroyalbikes.com',
    phone: '+91 98765 34567',
    address: '123, MG Road, Near Trinity Metro',
    city: 'Bangalore',
    state: 'Karnataka',
    region: 'South',
    managerName: 'Suresh Kumar'
  },
  'RE-CHN-004': {
    code: 'RE-CHN-004',
    name: 'Chennai Enfield Hub',
    email: 'chennai@enfieldhub.com',
    phone: '+91 98765 45678',
    address: '78-80, Anna Salai, T Nagar',
    city: 'Chennai',
    state: 'Tamil Nadu',
    region: 'South',
    managerName: 'Venkat Ramanan'
  },
  'RE-HYD-005': {
    code: 'RE-HYD-005',
    name: 'Hyderabad Royal Motorcycles',
    email: 'hyderabad@royalmotorcycles.com',
    phone: '+91 98765 56789',
    address: '234, Banjara Hills, Road No. 12',
    city: 'Hyderabad',
    state: 'Telangana',
    region: 'South',
    managerName: 'Anil Reddy'
  },
  'RE-KOL-006': {
    code: 'RE-KOL-006',
    name: 'Kolkata Enfield Motors',
    email: 'kolkata@enfieldmotors.com',
    phone: '+91 98765 67890',
    address: '56-58, Park Street, Near Park Hotel',
    city: 'Kolkata',
    state: 'West Bengal',
    region: 'East',
    managerName: 'Amit Chatterjee'
  },
  'RE-PUN-007': {
    code: 'RE-PUN-007',
    name: 'Pune Royal Dealership',
    email: 'pune@royaldealership.com',
    phone: '+91 98765 78901',
    address: '345, FC Road, Deccan Gymkhana',
    city: 'Pune',
    state: 'Maharashtra',
    region: 'West',
    managerName: 'Sandeep Patil'
  },
  'RE-AHM-008': {
    code: 'RE-AHM-008',
    name: 'Ahmedabad Enfield Plaza',
    email: 'ahmedabad@enfieldplaza.com',
    phone: '+91 98765 89012',
    address: '123, CG Road, Navrangpura',
    city: 'Ahmedabad',
    state: 'Gujarat',
    region: 'West',
    managerName: 'Kiran Patel'
  },
  'RE-JP-009': {
    code: 'RE-JP-009',
    name: 'Jaipur Royal Enfield',
    email: 'jaipur@royalenfield.com',
    phone: '+91 98765 90123',
    address: '67, MI Road, C-Scheme',
    city: 'Jaipur',
    state: 'Rajasthan',
    region: 'North',
    managerName: 'Rajesh Sharma'
  },
  'RE-LKO-010': {
    code: 'RE-LKO-010',
    name: 'Lucknow Enfield Showroom',
    email: 'lucknow@enfieldshowroom.com',
    phone: '+91 98765 01234',
    address: '89, Hazratganj, Near Halwasiya Crossing',
    city: 'Lucknow',
    state: 'Uttar Pradesh',
    region: 'North',
    managerName: 'Ankit Verma'
  }
};

/**
 * Get dealer information by dealer code
 * @param dealerCode - The dealer code (e.g., 'RE-MH-001')
 * @returns DealerInfo object or null if not found
 */
export function getDealerInfo(dealerCode: string): DealerInfo | null {
  return DEALER_DATABASE[dealerCode] || null;
}

/**
 * Get all dealers for a specific region
 * @param region - Region name (North, South, East, West)
 * @returns Array of DealerInfo objects
 */
export function getDealersByRegion(region: string): DealerInfo[] {
  return Object.values(DEALER_DATABASE).filter(
    dealer => dealer.region.toLowerCase() === region.toLowerCase()
  );
}

/**
 * Get all dealers for a specific state
 * @param state - State name
 * @returns Array of DealerInfo objects
 */
export function getDealersByState(state: string): DealerInfo[] {
  return Object.values(DEALER_DATABASE).filter(
    dealer => dealer.state.toLowerCase() === state.toLowerCase()
  );
}

/**
 * Get all dealers as an array (for dropdowns, etc.)
 * @returns Array of DealerInfo objects
 */
export function getAllDealers(): DealerInfo[] {
  return Object.values(DEALER_DATABASE);
}

/**
 * Search dealers by name or code
 * @param searchTerm - Search term
 * @returns Array of matching DealerInfo objects
 */
export function searchDealers(searchTerm: string): DealerInfo[] {
  const term = searchTerm.toLowerCase();
  return Object.values(DEALER_DATABASE).filter(
    dealer => 
      dealer.name.toLowerCase().includes(term) ||
      dealer.code.toLowerCase().includes(term) ||
      dealer.city.toLowerCase().includes(term)
  );
}

/**
 * Format dealer address for display
 * @param dealer - DealerInfo object
 * @returns Formatted address string
 */
export function formatDealerAddress(dealer: DealerInfo): string {
  return `${dealer.address}, ${dealer.city}, ${dealer.state}`;
}
