/**
 * 📍 Dados Mock - RouteStops Module
 * 
 * Dados de desenvolvimento para o módulo de paradas de rotas incluindo
 * documentos fiscais NFe/NFCe e diferentes tipos de paradas.
 * 
 * ✨ Cenários cobertos:
 * - Paradas de coleta com NFe
 * - Entregas com NFCe  
 * - Abastecimento sem documento
 * - Paradas de descanso
 * - Diferentes status e evidências
 */

import { RouteStop, FiscalDocument } from './route-stops.interface';

// ========================================
// 📄 DOCUMENTOS FISCAIS MOCK
// ========================================

export const mockFiscalDocuments: FiscalDocument[] = [
  {
    fiscalDocumentId: 'nfe_001_2024',
    documentType: 'NFe',
    documentNumber: '123456789',
    series: '001',
    accessKey: '31240114200166000196550010000000001234567890',
    issueDate: new Date('2024-01-14T08:00:00'),
    totalValue: 2500.00,
    productType: 'Eletrônicos',
    status: 'validated',
    emitter: {
      cnpj: '14.200.166/0001-96',
      name: 'TechStore Distribuidora Ltda',
      address: 'Av. Paulista, 1000 - São Paulo, SP'
    },
    receiver: {
      cpfCnpj: '98.765.432/0001-10',
      name: 'Loja TechMania',
      address: 'Rua das Flores, 123 - São Paulo, SP'
    },
    notes: 'Produtos eletrônicos diversos - notebooks e smartphones',
    tags: ['electronics', 'high-value', 'fragile'],
    createdAt: new Date('2024-01-14T08:00:00'),
    updatedAt: new Date('2024-01-14T08:00:00'),
    createdBy: 'user_001'
  },
  {
    fiscalDocumentId: 'nfce_002_2024',
    documentType: 'NFCe',
    documentNumber: '987654321',
    series: null, // NFCe pode não ter série
    accessKey: null, // Chave pode ser preenchida posteriormente
    issueDate: new Date('2024-01-14T10:30:00'),
    totalValue: 850.00,
    productType: 'Medicamentos',
    status: 'pending',
    emitter: {
      cnpj: '12.345.678/0001-90',
      name: 'Farmácia Central Ltda',
      address: 'Rua da Saúde, 456 - São Paulo, SP'
    },
    receiver: {
      cpfCnpj: '123.456.789-00',
      name: 'Maria Santos Silva',
      address: 'Rua das Flores, 123 - São Paulo, SP'
    },
    notes: 'Medicamentos controlados - manter refrigeração',
    tags: ['medicines', 'controlled', 'temperature-sensitive'],
    createdAt: new Date('2024-01-14T10:30:00'),
    updatedAt: new Date('2024-01-14T10:30:00'),
    createdBy: 'user_002'
  },
  {
    fiscalDocumentId: 'nfe_003_2024',
    documentType: 'NFe',
    documentNumber: '555666777',
    series: '002',
    accessKey: '31240115300204000189550020000000003556667771',
    issueDate: new Date('2024-01-15T07:00:00'),
    totalValue: 1200.00,
    productType: 'Alimentos',
    status: 'validated',
    emitter: {
      cnpj: '15.300.204/0001-89',
      name: 'Distribuidora Alimentos SA',
      address: 'Rod. Anhanguera, Km 25 - Osasco, SP'
    },
    receiver: {
      cpfCnpj: '99.888.777/0001-66',
      name: 'Supermercado Bom Preço',
      address: 'Av. São João, 789 - São Paulo, SP'
    },
    notes: 'Produtos alimentícios diversos - perecíveis',
    tags: ['food', 'perishable', 'grocery'],
    createdAt: new Date('2024-01-15T07:00:00'),
    updatedAt: new Date('2024-01-15T07:00:00'),
    createdBy: 'user_003'
  }
];

// ========================================
// 📍 PARADAS DE ROTA MOCK
// ========================================

export const mockRouteStops: RouteStop[] = [
  // 📦 PARADA 1: Coleta com NFe de Eletrônicos
  {
    id: 'stop_001_route_001',
    routeId: 'route_001',
    sequence: 1,
    type: 'pickup',
    location: {
      address: 'Av. Paulista, 1000 - Bela Vista, São Paulo - SP',
      coordinates: { lat: -23.5631, lng: -46.6554 },
      contact: 'João Silva',
      phone: '(11) 99999-9999',
      cep: '01310-100',
      city: 'São Paulo',
      state: 'SP',
      country: 'Brasil',
      facility: 'TechStore Distribuidora - CD Central',
      accessInstructions: 'Portão A - Apresentar documento na portaria'
    },
    scheduledTime: new Date('2024-01-15T08:00:00'),
    actualTime: undefined,
    estimatedDuration: 30,
    status: 'pending',
    packages: 5,
    weight: 150,
    volume: 2.5,
    referenceNumber: 'REF-TECH-001',
    fiscalDocument: mockFiscalDocuments[0],
    photos: [],
    signature: undefined,
    notes: 'Produtos frágeis - manuseio cuidadoso',
    attempts: 0,
    delayReason: undefined,
    temperature: undefined,
    createdAt: new Date('2024-01-14T16:00:00'),
    updatedAt: new Date('2024-01-14T16:00:00'),
    createdBy: 'user_001'
  },

  // 🚚 PARADA 2: Entrega com NFCe de Medicamentos
  {
    id: 'stop_002_route_001',
    routeId: 'route_001',
    sequence: 2,
    type: 'delivery',
    location: {
      address: 'Rua das Flores, 123 - Vila Madalena, São Paulo - SP',
      coordinates: { lat: -23.5505, lng: -46.6890 },
      contact: 'Maria Santos',
      phone: '(11) 88888-8888',
      cep: '05435-010',
      city: 'São Paulo',
      state: 'SP',
      country: 'Brasil',
      facility: 'Farmácia Central - Loja Vila Madalena',
      accessInstructions: 'Entrada pelos fundos - Horário comercial apenas'
    },
    scheduledTime: new Date('2024-01-15T10:30:00'),
    actualTime: undefined,
    estimatedDuration: 20,
    status: 'pending',
    packages: 3,
    weight: 75,
    volume: 1.2,
    referenceNumber: 'REF-FARM-002',
    fiscalDocument: mockFiscalDocuments[1],
    photos: [],
    signature: undefined,
    notes: 'Medicamentos controlados - conferir receituário',
    attempts: 0,
    delayReason: undefined,
    temperature: 8, // Refrigerado
    createdAt: new Date('2024-01-14T16:15:00'),
    updatedAt: new Date('2024-01-14T16:15:00'),
    createdBy: 'user_002'
  },

  // ⛽ PARADA 3: Combustível (sem documento fiscal)
  {
    id: 'stop_003_route_001',
    routeId: 'route_001',
    sequence: 3,
    type: 'fuel',
    location: {
      address: 'Posto Shell - Av. Rebouças, 3000, São Paulo - SP',
      coordinates: { lat: -23.5630, lng: -46.6729 },
      contact: 'Atendente do Posto',
      phone: '(11) 77777-7777',
      cep: '05402-600',
      city: 'São Paulo',
      state: 'SP',
      country: 'Brasil',
      facility: 'Posto Shell Express',
      accessInstructions: 'Pista para veículos comerciais - Bomba 4'
    },
    scheduledTime: new Date('2024-01-15T12:00:00'),
    actualTime: undefined,
    estimatedDuration: 30,
    status: 'pending',
    packages: undefined,
    weight: undefined,
    volume: undefined,
    referenceNumber: 'FUEL-001',
    fiscalDocument: undefined, // Combustível não requer NFe na parada
    photos: [],
    signature: undefined,
    notes: 'Abastecimento programado - tanque cheio',
    attempts: 0,
    delayReason: undefined,
    temperature: undefined,
    createdAt: new Date('2024-01-14T16:30:00'),
    updatedAt: new Date('2024-01-14T16:30:00'),
    createdBy: 'user_001'
  },

  // 🚚 PARADA 4: Entrega com NFe de Alimentos
  {
    id: 'stop_004_route_001',
    routeId: 'route_001',
    sequence: 4,
    type: 'delivery',
    location: {
      address: 'Av. São João, 789 - Centro, São Paulo - SP',
      coordinates: { lat: -23.5445, lng: -46.6390 },
      contact: 'Carlos Oliveira',
      phone: '(11) 66666-6666',
      cep: '01035-000',
      city: 'São Paulo',
      state: 'SP',
      country: 'Brasil',
      facility: 'Supermercado Bom Preço',
      accessInstructions: 'Dock de recebimento - Lateral direita do prédio'
    },
    scheduledTime: new Date('2024-01-15T14:30:00'),
    actualTime: undefined,
    estimatedDuration: 45,
    status: 'pending',
    packages: 8,
    weight: 300,
    volume: 5.0,
    referenceNumber: 'REF-SUPER-003',
    fiscalDocument: mockFiscalDocuments[2],
    photos: [],
    signature: undefined,
    notes: 'Produtos perecíveis - prioridade na descarga',
    attempts: 0,
    delayReason: undefined,
    temperature: 4, // Refrigerado
    createdAt: new Date('2024-01-14T16:45:00'),
    updatedAt: new Date('2024-01-14T16:45:00'),
    createdBy: 'user_003'
  },

  // 😴 PARADA 5: Descanso obrigatório
  {
    id: 'stop_005_route_001',
    routeId: 'route_001',
    sequence: 5,
    type: 'rest',
    location: {
      address: 'Posto de Serviços BR - Rod. Presidente Dutra, Km 180',
      coordinates: { lat: -23.1234, lng: -45.9876 },
      contact: 'Atendimento 24h',
      phone: '(12) 55555-5555',
      cep: '12345-000',
      city: 'Guarulhos',
      state: 'SP',
      country: 'Brasil',
      facility: 'Posto BR - Área de Descanso',
      accessInstructions: 'Estacionamento para caminhões - Área coberta'
    },
    scheduledTime: new Date('2024-01-15T16:00:00'),
    actualTime: undefined,
    estimatedDuration: 120, // 2 horas de descanso
    status: 'pending',
    packages: undefined,
    weight: undefined,
    volume: undefined,
    referenceNumber: 'REST-001',
    fiscalDocument: undefined,
    photos: [],
    signature: undefined,
    notes: 'Descanso obrigatório - Lei do motorista',
    attempts: 0,
    delayReason: undefined,
    temperature: undefined,
    createdAt: new Date('2024-01-14T17:00:00'),
    updatedAt: new Date('2024-01-14T17:00:00'),
    createdBy: 'user_001'
  }
];

// ========================================
// 📍 PARADAS COM EVIDÊNCIAS (SIMULANDO CONCLUSÃO)
// ========================================

export const mockCompletedRouteStops: RouteStop[] = [
  {
    ...mockRouteStops[0],
    id: 'stop_completed_001',
    status: 'completed',
    actualTime: new Date('2024-01-15T08:25:00'),
    actualDuration: 25,
    photos: [
      'https://example.com/photos/pickup_001_package.jpg',
      'https://example.com/photos/pickup_001_receipt.jpg'
    ],
    signature: 'https://example.com/signatures/pickup_001_signature.png',
    completionEvidence: {
      photoPackage: 'https://example.com/evidence/pickup_001_package.jpg',
      photoReceipt: 'https://example.com/evidence/pickup_001_receipt.jpg',
      digitalSignature: 'https://example.com/evidence/pickup_001_signature.png',
      recipientName: 'João Silva - Responsável CD',
      completionTime: new Date('2024-01-15T08:25:00'),
      latitude: -23.5631,
      longitude: -46.6554
    },
    notes: 'Coleta realizada sem intercorrências - 5 volumes conferidos',
    attempts: 1
  },
  {
    ...mockRouteStops[1],
    id: 'stop_completed_002',
    status: 'completed',
    actualTime: new Date('2024-01-15T10:45:00'),
    actualDuration: 15,
    photos: [
      'https://example.com/photos/delivery_001_delivery.jpg',
      'https://example.com/photos/delivery_001_recipient.jpg'
    ],
    signature: 'https://example.com/signatures/delivery_001_signature.png',
    completionEvidence: {
      photoPackage: 'https://example.com/evidence/delivery_001_packages.jpg',
      photoReceipt: 'https://example.com/evidence/delivery_001_receipt.jpg',
      digitalSignature: 'https://example.com/evidence/delivery_001_signature.png',
      recipientName: 'Maria Santos - Farmacêutica Responsável',
      completionTime: new Date('2024-01-15T10:45:00'),
      latitude: -23.5505,
      longitude: -46.6890
    },
    notes: 'Entrega concluída - medicamentos conferidos e armazenados adequadamente',
    attempts: 1
  }
];

// ========================================
// 📊 DADOS ESTATÍSTICOS MOCK
// ========================================

export const mockRouteStopsStats = {
  totalStops: 5,
  completedStops: 2,
  pendingStops: 3,
  completionRate: 40,
  averageStopDuration: 25,
  
  byType: {
    pickup: 1,
    delivery: 2,
    fuel: 1,
    rest: 1
  },
  
  byStatus: {
    pending: 3,
    completed: 2,
    failed: 0,
    skipped: 0
  },
  
  documentsOverview: {
    totalDocuments: 3,
    nfeCount: 2,
    nfceCount: 1,
    totalValue: 4550.00,
    validatedDocuments: 2,
    pendingValidation: 1
  }
};

// ========================================
// 🎯 HELPERS PARA DESENVOLVIMENTO
// ========================================

export function getRouteStopsByRouteId(routeId: string): RouteStop[] {
  return mockRouteStops.filter(stop => stop.routeId === routeId);
}

export function getRouteStopById(stopId: string): RouteStop | undefined {
  return mockRouteStops.find(stop => stop.id === stopId);
}

export function getFiscalDocumentById(documentId: string): FiscalDocument | undefined {
  return mockFiscalDocuments.find(doc => doc.fiscalDocumentId === documentId);
}

export function getRouteStopsByType(type: 'pickup' | 'delivery' | 'rest' | 'fuel'): RouteStop[] {
  return mockRouteStops.filter(stop => stop.type === type);
}

export function getRouteStopsByStatus(status: 'pending' | 'completed' | 'failed' | 'skipped'): RouteStop[] {
  return mockRouteStops.filter(stop => stop.status === status);
}

// ========================================
// 🔄 SIMULAÇÃO DE OTIMIZAÇÃO
// ========================================

export const mockOptimizedSequence = [
  mockRouteStops[0], // Pickup first
  mockRouteStops[2], // Fuel (nearby)
  mockRouteStops[1], // Delivery 1
  mockRouteStops[3], // Delivery 2  
  mockRouteStops[4]  // Rest last
];

export const mockOptimizationResult = {
  distanceReduction: 15.5, // km
  timeReduction: 45, // minutos
  fuelSavings: 8.2, // litros
  costSavings: 25.50 // reais
}; 