import 'package:flutter_riverpod/flutter_riverpod.dart';
import '../../core/auth/role_provider.dart';

/// 系统 Banner 模型
class SysBanner {
  final String id;
  final String imageUrl;
  final String? linkUrl;
  final String? title;

  const SysBanner({
    required this.id,
    required this.imageUrl,
    this.linkUrl,
    this.title,
  });

  static const mockBanners = [
    SysBanner(id: '1', imageUrl: 'assets/img/banner_1.png', title: 'OA系统升级通知'),
    SysBanner(
      id: '2',
      imageUrl: 'assets/img/banner_2.png',
      linkUrl: 'https://example.com',
      title: '2026年度预算管理',
    ),
    SysBanner(id: '3', imageUrl: 'assets/img/banner_3.png', title: '端午节放假安排'),
  ];
}

/// 工作台首页聚合数据模型
///
/// 角色权限优先级：admin > finance > manager > employee
/// 数据全部使用 mock，角色从权限派生。
class HomeSummary {
  /// 用户角色：admin / finance / manager / employee
  final String userRole;

  // ── 员工版：个人快捷看板 ──
  final double monthlyReimbursement; // 本月累计报销（本人已付款总额 ¥）
  final int monthlySubmittedCount; // 本月已提单据（本人提交总数 笔）

  // ── 经理版：待审批 + 部门范围 ──
  final int pendingApprovalCount; // 待审批数（红色角标）
  final double deptMonthlyReimbursement; // 部门本月累计报销
  final int deptMonthlySubmittedCount; // 部门本月已提单据
  final int deptPendingDocuments; // 部门在途单据

  // ── 财务/管理员版 ──
  final double paidTotal; // 本月已支付总额
  final double pendingPaymentTotal; // 待付款总额
  final double abnormalReturns; // 本周异常退回

  const HomeSummary({
    this.userRole = 'employee',
    this.monthlyReimbursement = 0,
    this.monthlySubmittedCount = 0,
    this.pendingApprovalCount = 0,
    this.deptMonthlyReimbursement = 0,
    this.deptMonthlySubmittedCount = 0,
    this.deptPendingDocuments = 0,
    this.paidTotal = 0,
    this.pendingPaymentTotal = 0,
    this.abnormalReturns = 0,
  });
}

/// Banner Provider — 返回模拟 Banner 列表
final bannerProvider = Provider<List<SysBanner>>((ref) {
  return SysBanner.mockBanners;
});

/// 首页数据 Provider — 返回模拟 HomeSummary
///
/// 修改 userRole 可测试不同角色视图：
///   'employee' → 员工版
///   'manager'  → 经理版
///   'finance'  → 财务版
///   'admin'    → 管理员版
final homeSummaryProvider = FutureProvider<HomeSummary>((ref) async {
  final role = ref.watch(currentRoleProvider);
  return HomeSummary(
    userRole: role,
    // 员工版数据
    monthlyReimbursement: 12800.50,
    monthlySubmittedCount: 8,
    // 经理版数据
    pendingApprovalCount: 5,
    deptMonthlyReimbursement: 156800.00,
    deptMonthlySubmittedCount: 42,
    deptPendingDocuments: 15,
    // 财务/管理员版数据
    paidTotal: 896500.00,
    pendingPaymentTotal: 283200.50,
    abnormalReturns: 12800.00,
  );
});
