
import { SeasonType, TireCondition, Customer, StorageRecord, StorageStatus, NewsEntry, SystemUser, WorkOrder, Appointment, WorkCategory, Vehicle, InventoryItem } from '../types';
import { addDays, format, addHours } from 'date-fns';

const todayStr = format(new Date(), 'yyyy-MM-dd');
const tomorrowStr = format(addDays(new Date(), 1), 'yyyy-MM-dd');
const yesterdayStr = format(addDays(new Date(), -1), 'yyyy-MM-dd');

export const MOCK_NEWS: NewsEntry[] = [
  {
    id: '1',
    title: 'Wartungsarbeiten am Server',
    content: 'Am Sonntag, den 25.02. finden zwischen 02:00 und 04:00 Uhr Wartungsarbeiten an der zentralen Datenbank statt.',
    type: 'warning',
    date: '2025-02-20'
  },
  {
    id: '2',
    title: 'Neue Saison Vorbereitung',
    content: 'Bitte überprüfen Sie die Bestände an Reifensäcken für die kommende Wechselsaison.',
    type: 'info',
    date: '2025-02-18'
  },
  {
    id: '3',
    title: 'Mitarbeiter des Monats',
    content: 'Glückwunsch an Max für die meisten erledigten Aufträge im letzten Monat!',
    type: 'success',
    date: '2025-03-01'
  }
];

export const MOCK_SYSTEM_USERS: SystemUser[] = [
  { id: 99, username: 'global_admin', email: 'it@dowo.tech', role_id: 0, onlinenow: true, last_sessionid: Date.now() / 1000, mustChangePassword: false, workshop_id: 'W1', technicianId: 't_global' },
  { id: 1, username: 'admin', email: 'chef@autohaus.de', role_id: 1, onlinenow: true, last_sessionid: Date.now() / 1000, mustChangePassword: false, workshop_id: 'W1', technicianId: 't_admin' },
  { id: 2, username: 'verkauf_tom', email: 't.verkauf@autohaus.de', role_id: 2, onlinenow: false, last_sessionid: (Date.now() / 1000) - 3600, mustChangePassword: false, workshop_id: 'W1', technicianId: 't_tom' },
  { id: 3, username: 'service_anna', email: 'a.schmidt@autohaus.de', role_id: 3, onlinenow: true, last_sessionid: (Date.now() / 1000) - 120, mustChangePassword: false, workshop_id: 'W1', technicianId: 't_anna' },
  { id: 4, username: 'lager_klaus', email: 'k.kleber@autohaus.de', role_id: 4, onlinenow: false, last_sessionid: (Date.now() / 1000) - 86400, mustChangePassword: true, workshop_id: 'W1', technicianId: 't_klaus' },
  
  // SALES & SERVICE
  { id: 11, username: 'verkauf_julia', email: 'j.sommer@autohaus.de', role_id: 2, onlinenow: true, last_sessionid: Date.now() / 1000, mustChangePassword: false, workshop_id: 'W1', technicianId: 't5' },
  { id: 12, username: 'service_peter', email: 'p.winter@autohaus.de', role_id: 3, onlinenow: false, last_sessionid: Date.now() / 1000, mustChangePassword: false, workshop_id: 'W1', technicianId: 't6' },
  { id: 13, username: 'lager_hans', email: 'h.dampf@autohaus.de', role_id: 4, onlinenow: true, last_sessionid: Date.now() / 1000, mustChangePassword: false, workshop_id: 'W1', technicianId: 't7' },

  // MECHANICS (Linked to Technician IDs in api.ts)
  { id: 5, username: 'mech_max', email: 'max.m@autohaus.de', role_id: 5, onlinenow: true, last_sessionid: Date.now() / 1000, mustChangePassword: false, workshop_id: 'W1', technicianId: 't1' },
  { id: 6, username: 'mech_lisa', email: 'lisa.l@autohaus.de', role_id: 5, onlinenow: true, last_sessionid: Date.now() / 1000, mustChangePassword: false, workshop_id: 'W1', technicianId: 't2' },
  { id: 7, username: 'mech_alex', email: 'alex.azubi@autohaus.de', role_id: 5, onlinenow: true, last_sessionid: Date.now() / 1000, mustChangePassword: false, workshop_id: 'W1', technicianId: 't3' },
  { id: 8, username: 'mech_bernd', email: 'bernd.b@autohaus.de', role_id: 5, onlinenow: false, last_sessionid: Date.now() / 1000, mustChangePassword: false, workshop_id: 'W1', technicianId: 't4' },
  { id: 10, username: 'admin_hamburg', email: 'hamburg@dowo.tech', role_id: 1, onlinenow: false, last_sessionid: null, mustChangePassword: false, workshop_id: 'W2', technicianId: 't_admin_hh' },

  // DEMO USERS
  { id: 901, username: 'demo_admin', role_id: 1, workshop_id: 'W1', technicianId: 't_admin', active: true, email: 'admin@demo.test', onlinenow: false, last_sessionid: null },
  { id: 902, username: 'demo_verkauf', role_id: 2, workshop_id: 'W1', technicianId: 't5', active: true, email: 'verkauf@demo.test', onlinenow: false, last_sessionid: null },
  { id: 903, username: 'demo_service', role_id: 3, workshop_id: 'W1', technicianId: 't6', active: true, email: 'service@demo.test', onlinenow: false, last_sessionid: null },
  { id: 904, username: 'demo_lager', role_id: 4, workshop_id: 'W1', technicianId: 't7', active: true, email: 'lager@demo.test', onlinenow: false, last_sessionid: null },
  { id: 905, username: 'demo_mechaniker', role_id: 5, workshop_id: 'W1', technicianId: 't1', active: true, email: 'mechaniker@demo.test', onlinenow: false, last_sessionid: null },
];

export const MOCK_CUSTOMERS: Customer[] = [
  { id: 'c1', customerNumber: '1001', salutation: 'Herr', firstName: 'Max', lastName: 'Mustermann', email: 'max@example.com', phone: '0171 111111', phone2: '089 123456', street: 'Musterstraße 1', zip: '12345', city: 'Musterstadt', workshopId: 'W1' },
  { id: 'c2', customerNumber: '1002', salutation: 'Frau', firstName: 'Sabine', lastName: 'Müller', email: 's.mueller@test.de', phone: '0172 222222', street: 'Bahnhofsweg 5', zip: '12345', city: 'Musterstadt', workshopId: 'W1' },
  { id: 'c3', customerNumber: '1003', salutation: 'Firma', firstName: '', lastName: 'Bau GmbH', email: 'info@baugmbh.de', phone: '089 333333', phone2: '0151 555666', street: 'Industriepark 9', zip: '12345', city: 'Musterstadt', workshopId: 'W1' },
  { id: 'c4', customerNumber: '1004', salutation: 'Herr', firstName: 'Tim', lastName: 'Tester', email: 'tim@test.com', phone: '0175 444444', street: 'Testweg 99', zip: '54321', city: 'Testdorf', workshopId: 'W1' },
  { id: 'c5', customerNumber: '1005', salutation: 'Frau', firstName: 'Julia', lastName: 'Jäger', email: 'j.jaeger@web.de', phone: '0160 555555', street: 'Waldweg 3', zip: '12345', city: 'Musterstadt', workshopId: 'W1' },
  { id: 'c6', customerNumber: '2001', salutation: 'Frau', firstName: 'Sarah', lastName: 'Nordlicht', email: 'sarah@hamburg-mail.de', phone: '040 998877', street: 'Reeperbahn 12', zip: '20359', city: 'Hamburg', workshopId: 'W2' },
  { id: 'c7', customerNumber: '1006', salutation: 'Herr', firstName: 'Peter', lastName: 'Parker', email: 'spidey@web.net', phone: '0151 999888', street: 'Netzweg 4', zip: '12345', city: 'Musterstadt', workshopId: 'W1' },
  { id: 'c8', customerNumber: '1007', salutation: 'Firma', firstName: '', lastName: 'Logistik Express', email: 'fuhrpark@logistik.de', phone: '089 123123', street: 'Frachtstraße 1', zip: '12345', city: 'Musterstadt', workshopId: 'W1' },
];

export const MOCK_VEHICLES: Vehicle[] = [
    { id: 'v1', customerId: 'c1', licensePlate: 'M-XY 123', manufacturer: 'VW', model: 'Golf 8', vin: 'WVWZZZCDZLW00000', firstRegistration: '2021-05-01', fuelType: 'Benzin', nextHU: '2024-05' },
    { id: 'v2', customerId: 'c2', licensePlate: 'M-AB 456', manufacturer: 'Audi', model: 'A4 Avant', vin: 'WAUZZZF4ZKA00000', fuelType: 'Diesel', nextHU: '2025-02' },
    { id: 'v3', customerId: 'c3', licensePlate: 'M-BG 777', manufacturer: 'Mercedes', model: 'Sprinter', fuelType: 'Diesel', nextHU: '2024-11' },
    { id: 'v4', customerId: 'c4', licensePlate: 'T-EST 99', manufacturer: 'Tesla', model: 'Model Y', fuelType: 'Elektrofahrzeug', nextHU: '2026-06' },
    { id: 'v5', customerId: 'c5', licensePlate: 'M-JJ 55', manufacturer: 'BMW', model: 'X3', fuelType: 'Pluginhybrid', nextHU: '2024-08' },
    { id: 'v6', customerId: 'c7', licensePlate: 'M-PP 2020', manufacturer: 'Audi', model: 'A3', fuelType: 'Benzin', nextHU: '2025-01' },
    { id: 'v7', customerId: 'c8', licensePlate: 'M-LO 100', manufacturer: 'Ford', model: 'Transit', fuelType: 'Diesel', nextHU: '2024-09' },
    { id: 'v8', customerId: 'c8', licensePlate: 'M-LO 101', manufacturer: 'Ford', model: 'Transit', fuelType: 'Diesel', nextHU: '2024-09' },
];

export const MOCK_RECORDS: StorageRecord[] = [
  {
    id: 'r1', customerId: 'c1', licensePlate: 'M-XY 123', vehicleManufacturer: 'VW', vehicleModel: 'Golf 8', season: SeasonType.WINTER,
    tireCount: 4, tireDimension: '205/55 R16', loadIndex: '91', speedIndex: 'H', manufacturer: 'Continental', dot: '3521',
    hasStaggeredTires: false, rimsIncluded: 'Ja', rimType: 'Stahl', treadDepth: { vl: 6.5, vr: 6.5, hl: 7.0, hr: 7.0 },
    condition: TireCondition.GOOD, location: '003', status: StorageStatus.STORED, checkInUser: 'Max Mechaniker',
    notes: 'Radkappen im Kofferraum', accessories: 'Radbolzen: Ja', images: [],
    checkInDate: format(addDays(new Date(), -45), 'yyyy-MM-dd'), expectedPickUpDate: format(addDays(new Date(), 120), 'yyyy-MM-dd'),
    servicesRequested: ['Wuchten'], workshopId: 'W1'
  },
  {
    id: 'r2', customerId: 'c2', licensePlate: 'M-AB 456', vehicleManufacturer: 'Audi', vehicleModel: 'A4 Avant', season: SeasonType.SUMMER,
    tireCount: 4, tireDimension: '225/45 R17', loadIndex: '94', speedIndex: 'Y', manufacturer: 'Michelin', dot: '1222',
    hasStaggeredTires: false, rimsIncluded: 'Ja', rimType: 'Alu', treadDepth: { vl: 3.5, vr: 3.5, hl: 4.0, hr: 4.0 },
    condition: TireCondition.REPLACE_SUGGESTED, location: '105', status: StorageStatus.STORED, checkInUser: 'Max Mechaniker',
    notes: 'VR Kratzer an Felge', accessories: 'Nabendeckel fehlen', images: [],
    checkInDate: format(addDays(new Date(), -180), 'yyyy-MM-dd'), expectedPickUpDate: format(addDays(new Date(), 10), 'yyyy-MM-dd'),
    servicesRequested: [], workshopId: 'W1'
  },
  {
    id: 'r3', customerId: 'c3', licensePlate: 'M-BG 777', vehicleManufacturer: 'Mercedes', vehicleModel: 'Sprinter', season: SeasonType.ALL_SEASON,
    tireCount: 4, tireDimension: '235/65 R16', loadIndex: '115', speedIndex: 'R', manufacturer: 'Hankook', dot: '4023',
    hasStaggeredTires: false, rimsIncluded: 'Ja', rimType: 'Stahl', treadDepth: { vl: 8.0, vr: 8.0, hl: 8.2, hr: 8.2 },
    condition: TireCondition.GOOD, location: '202', status: StorageStatus.STORED, checkInUser: 'Lager Klaus',
    notes: 'Kundenräder', accessories: '', images: [],
    checkInDate: format(addDays(new Date(), -10), 'yyyy-MM-dd'), expectedPickUpDate: '',
    servicesRequested: ['Reinigung'], workshopId: 'W1'
  },
  {
    id: 'r4', customerId: 'c4', licensePlate: 'T-EST 99', vehicleManufacturer: 'Tesla', vehicleModel: 'Model Y', season: SeasonType.WINTER,
    tireCount: 4, tireDimension: '255/45 R19', loadIndex: '104', speedIndex: 'W', manufacturer: 'Pirelli', dot: '0124',
    hasStaggeredTires: true, rimsIncluded: 'Ja', rimType: 'Alu', treadDepth: { vl: 7.5, vr: 7.5, hl: 7.0, hr: 7.0 },
    tireDimensionRear: '275/40 R19', loadIndexRear: '108', speedIndexRear: 'W', manufacturerRear: 'Pirelli', dotRear: '0124',
    condition: TireCondition.GOOD, location: '012', status: StorageStatus.STORED, checkInUser: 'Service Anna',
    notes: '', accessories: 'Bluetooth Sensoren', images: [],
    checkInDate: format(addDays(new Date(), -5), 'yyyy-MM-dd'), expectedPickUpDate: '',
    servicesRequested: [], workshopId: 'W1'
  },
  {
    id: 'r5', customerId: 'c5', licensePlate: 'M-JJ 55', vehicleManufacturer: 'BMW', vehicleModel: 'X3', season: SeasonType.SUMMER,
    tireCount: 4, tireDimension: '245/50 R19', loadIndex: '100', speedIndex: 'W', manufacturer: 'Bridgestone', dot: '2020',
    hasStaggeredTires: false, rimsIncluded: 'Nein', rimType: 'Stahl', treadDepth: { vl: 2.0, vr: 2.0, hl: 3.0, hr: 3.0 },
    condition: TireCondition.CRITICAL, location: '999', status: StorageStatus.PICKED_UP, checkInUser: 'Max Mechaniker',
    notes: 'Kunde informiert über Profil', accessories: '', images: [],
    checkInDate: format(addDays(new Date(), -365), 'yyyy-MM-dd'), expectedPickUpDate: format(addDays(new Date(), -1), 'yyyy-MM-dd'),
    servicesRequested: [], workshopId: 'W1'
  },
  // Extra Records for filling
  {
    id: 'r6', customerId: 'c7', licensePlate: 'M-PP 2020', vehicleManufacturer: 'Audi', vehicleModel: 'A3', season: SeasonType.WINTER,
    tireCount: 4, tireDimension: '205/55 R16', loadIndex: '91', speedIndex: 'H', manufacturer: 'Dunlop', dot: '1522',
    hasStaggeredTires: false, rimsIncluded: 'Ja', rimType: 'Alu', treadDepth: { vl: 5.0, vr: 5.0, hl: 6.0, hr: 6.0 },
    condition: TireCondition.GOOD, location: '004', status: StorageStatus.STORED, checkInUser: 'Service Anna',
    notes: '', accessories: '', images: [],
    checkInDate: format(addDays(new Date(), -20), 'yyyy-MM-dd'), 
    expectedPickUpDate: '', servicesRequested: [], workshopId: 'W1'
  }
];

export const MOCK_PARTS: InventoryItem[] = [
    { id: 'p1', articleNumber: 'FILTER-001', name: 'Ölfilter VW Golf 7/8', category: 'Ersatzteile', manufacturer: 'Mann', quantity: 15, unit: 'stk', minQuantity: 5, purchasePrice: 4.50, salesPrice: 12.90, location: 'REG-A-01', workshopId: 'W1' },
    { id: 'p2', articleNumber: 'OIL-5W30', name: 'Motoröl 5W30 Longlife', category: 'Betriebsstoffe', manufacturer: 'Castrol', quantity: 200, unit: 'l', minQuantity: 60, purchasePrice: 6.20, salesPrice: 18.50, location: 'TANK-1', workshopId: 'W1' },
    { id: 'p3', articleNumber: 'BREMSE-V-A4', name: 'Bremsbeläge VA Audi A4', category: 'Ersatzteile', manufacturer: 'ATE', quantity: 2, unit: 'set', minQuantity: 4, purchasePrice: 45.00, salesPrice: 110.00, location: 'REG-B-03', workshopId: 'W1' }, // Low Stock!
    { id: 'p4', articleNumber: 'WISCH-U-GOLF', name: 'Wischblätter Set Golf 8', category: 'Ersatzteile', manufacturer: 'Bosch', quantity: 8, unit: 'set', minQuantity: 5, purchasePrice: 12.00, salesPrice: 35.00, location: 'THEKE', workshopId: 'W1' },
    { id: 'p5', articleNumber: 'ADBLUE', name: 'AdBlue', category: 'Betriebsstoffe', manufacturer: 'ChemWorks', quantity: 10, unit: 'l', minQuantity: 20, purchasePrice: 0.80, salesPrice: 2.50, location: 'L-G-01', workshopId: 'W1' }, // Low Stock!
    { id: 'p6', articleNumber: 'LAMPE-H7', name: 'Glühlampe H7 Longlife', category: 'Ersatzteile', manufacturer: 'Osram', quantity: 50, unit: 'stk', minQuantity: 10, purchasePrice: 2.50, salesPrice: 9.90, location: 'KLEIN-05', workshopId: 'W1' },
    { id: 'p7', articleNumber: 'TYRE-2055516-W', name: 'Continental WinterContact TS870 205/55 R16 91H', category: 'Reifen', manufacturer: 'Continental', quantity: 16, unit: 'stk', minQuantity: 8, purchasePrice: 75.00, salesPrice: 110.00, location: 'LAGER-R1', workshopId: 'W1' },
    { id: 'p8', articleNumber: 'TYRE-2254517-S', name: 'Michelin Pilot Sport 4 225/45 R17 91Y', category: 'Reifen', manufacturer: 'Michelin', quantity: 8, unit: 'stk', minQuantity: 4, purchasePrice: 95.00, salesPrice: 145.00, location: 'LAGER-R2', workshopId: 'W1' },
    { id: 'p9', articleNumber: 'TYRE-1956515-A', name: 'Goodyear Vector 4Seasons 195/65 R15 91V', category: 'Reifen', manufacturer: 'Goodyear', quantity: 24, unit: 'stk', minQuantity: 12, purchasePrice: 60.00, salesPrice: 85.00, location: 'LAGER-R3', workshopId: 'W1' },
];

export const MOCK_LOGS: any[] = [
    { id: 'l1', timestamp: format(addHours(new Date(), -2), 'dd.MM.yyyy HH:mm:ss'), user: 'Max Mechaniker', type: 'status_change', action: 'Auftrag gestartet', details: 'Auftrag AU-100051 (M-AB 456) gestartet.', workshopId: 'W1' },
    { id: 'l2', timestamp: format(addHours(new Date(), -24), 'dd.MM.yyyy HH:mm:ss'), user: 'Lager Klaus', type: 'auslagerung', action: 'Neu-Einlagerung', details: 'M-XY 123 an Ort 003.', workshopId: 'W1' },
    { id: 'l3', timestamp: format(addHours(new Date(), -25), 'dd.MM.yyyy HH:mm:ss'), user: 'Service Anna', type: 'finance', action: 'Zahlung / Status', details: 'Rechnung RE-2025-1001 bezahlt (Bar).', workshopId: 'W1' },
    { id: 'l4', timestamp: format(addHours(new Date(), -48), 'dd.MM.yyyy HH:mm:ss'), user: 'Admin', type: 'edit', action: 'Artikel bearbeitet', details: 'Preis für 5W30 angepasst.', workshopId: 'W1' },
    { id: 'l5', timestamp: format(addHours(new Date(), -50), 'dd.MM.yyyy HH:mm:ss'), user: 'System', type: 'audit', action: 'Backup', details: 'Automatisches Backup erstellt.', workshopId: 'W1' },
];

export const MOCK_ORDERS = []; // Will be populated dynamically in api.ts to ensure dates are correct
export const MOCK_APPOINTMENTS = []; // Will be populated dynamically in api.ts