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

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

final mockOvertimes = <OvertimeModel>[
  OvertimeModel(
    id: 'ot-001',
    applicationNo: 'OT202605001',
    applicantId: 'u-001',
    applicantName: '张三',
    deptId: 'dept-001',
    deptName: '市场部',
    otDate: DateTime(2026, 5, 20),
    startTime: DateTime(2026, 5, 20, 18, 0),
    endTime: DateTime(2026, 5, 20, 21, 0),
    otHours: 3.0,
    otType: '工作日加班',
    compensationType: '加班费',
    reason: '项目上线前紧急测试',
    status: 'pending',
    createTime: DateTime(2026, 5, 20),
    updateTime: DateTime(2026, 5, 20),
    approvalRecords: [
      ApprovalRecord(
        id: 'ar-ot-001',
        bizId: 'ot-001',
        bizType: 'overtime',
        approverId: 'u-mgr',
        approverName: '李四',
        approvalLevel: 1,
        action: 'pending',
        opinion: '',
        approvalTime: DateTime(2026, 5, 20),
      ),
    ],
  ),
  OvertimeModel(
    id: 'ot-002',
    applicationNo: 'OT202605002',
    applicantId: 'u-002',
    applicantName: '王五',
    deptId: 'dept-002',
    deptName: '技术部',
    otDate: DateTime(2026, 5, 18),
    startTime: DateTime(2026, 5, 18, 9, 0),
    endTime: DateTime(2026, 5, 18, 18, 0),
    otHours: 8.0,
    otType: '休息日加班',
    compensationType: '调休',
    reason: '系统架构升级',
    status: 'approved',
    createTime: DateTime(2026, 5, 17),
    updateTime: DateTime(2026, 5, 19),
    approvalRecords: [
      ApprovalRecord(
        id: 'ar-ot-002',
        bizId: 'ot-002',
        bizType: 'overtime',
        approverId: 'u-mgr',
        approverName: '李四',
        approvalLevel: 1,
        action: 'approve',
        opinion: '同意',
        approvalTime: DateTime(2026, 5, 19),
      ),
    ],
  ),
  OvertimeModel(
    id: 'ot-003',
    applicationNo: 'OT202605003',
    applicantId: 'u-003',
    applicantName: '赵六',
    deptId: 'dept-003',
    deptName: '财务部',
    otDate: DateTime(2026, 5, 25),
    startTime: DateTime(2026, 5, 25, 19, 0),
    endTime: DateTime(2026, 5, 25, 22, 0),
    otHours: 3.0,
    otType: '工作日加班',
    compensationType: '加班费',
    reason: '季度财务报表汇总',
    status: 'pending',
    createTime: DateTime(2026, 5, 25),
    updateTime: DateTime(2026, 5, 25),
    approvalRecords: [
      ApprovalRecord(
        id: 'ar-ot-003',
        bizId: 'ot-003',
        bizType: 'overtime',
        approverId: 'u-mgr',
        approverName: '李四',
        approvalLevel: 1,
        action: 'pending',
        opinion: '',
        approvalTime: DateTime(2026, 5, 25),
      ),
    ],
  ),
];

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

final overtimeListProvider = FutureProvider<List<OvertimeModel>>((ref) async {
  ref.watch(overtimeStatusFilterProvider);
  ref.watch(overtimePageProvider);
  final status = ref.read(overtimeStatusFilterProvider);
  if (status.isEmpty) return mockOvertimes;
  return mockOvertimes.where((e) => e.status == status).toList();
});
