import 'package:flutter_riverpod/flutter_riverpod.dart';
import '../../shared/models/approval_status.dart';
import 'vehicle_model.dart';

final vehicleStatusFilterProvider = StateProvider<String>((ref) => '');

final vehiclePageProvider = StateProvider<int>((ref) => 1);

final mockVehicles = <VehicleModel>[
  VehicleModel(
    id: 'veh-001',
    applicationNo: 'VH202605001',
    applicantId: 'u-001',
    applicantName: '张三',
    deptId: 'dept-001',
    deptName: '市场部',
    vehicleType: '轿车',
    purpose: '客户拜访',
    startTime: DateTime(2026, 5, 22, 8, 0),
    endTime: DateTime(2026, 5, 22, 18, 0),
    origin: '公司总部',
    destination: '深圳分公司',
    passengerCount: 3,
    driver: '刘师傅',
    licensePlate: '京A·88888',
    estimatedMileage: 120.0,
    estimatedCost: 500.0,
    reason: '拜访重要客户，需前往深圳',
    status: 'pending',
    createTime: DateTime(2026, 5, 20),
    updateTime: DateTime(2026, 5, 20),
    approvalRecords: [
      ApprovalRecord(
        id: 'ar-vh-001',
        bizId: 'veh-001',
        bizType: 'vehicle',
        approverId: 'u-mgr',
        approverName: '李四',
        approvalLevel: 1,
        action: 'pending',
        opinion: '',
        approvalTime: DateTime(2026, 5, 20),
      ),
    ],
  ),
  VehicleModel(
    id: 'veh-002',
    applicationNo: 'VH202605002',
    applicantId: 'u-002',
    applicantName: '王五',
    deptId: 'dept-002',
    deptName: '技术部',
    vehicleType: 'SUV',
    purpose: '设备运输',
    startTime: DateTime(2026, 5, 25, 9, 0),
    endTime: DateTime(2026, 5, 25, 17, 0),
    origin: '公司仓库',
    destination: '数据中心',
    passengerCount: 2,
    driver: '王师傅',
    licensePlate: '京B·66666',
    estimatedMileage: 60.0,
    estimatedCost: 300.0,
    reason: '运送服务器设备至数据中心',
    status: 'approved',
    createTime: DateTime(2026, 5, 23),
    updateTime: DateTime(2026, 5, 24),
    approvalRecords: [
      ApprovalRecord(
        id: 'ar-vh-002',
        bizId: 'veh-002',
        bizType: 'vehicle',
        approverId: 'u-mgr',
        approverName: '李四',
        approvalLevel: 1,
        action: 'approve',
        opinion: '同意，注意安全',
        approvalTime: DateTime(2026, 5, 24),
      ),
    ],
  ),
];

final vehicleListProvider = FutureProvider<List<VehicleModel>>((ref) async {
  ref.watch(vehicleStatusFilterProvider);
  ref.watch(vehiclePageProvider);
  final status = ref.read(vehicleStatusFilterProvider);
  if (status.isEmpty) return mockVehicles;
  return mockVehicles.where((e) => e.status == status).toList();
});
