import '../../core/i18n/app_localizations.dart';

enum ApprovalStatus {
  draft,
  pending,
  approved,
  rejected,
  withdrawn;

  /// 返回本地化的状态标签文本
  String label(AppLocalizations l10n) {
    switch (this) {
      case ApprovalStatus.draft:
        return l10n.get('statusDraft');
      case ApprovalStatus.pending:
        return l10n.get('statusWaitApprove');
      case ApprovalStatus.approved:
        return l10n.get('statusApproved');
      case ApprovalStatus.rejected:
        return l10n.get('statusRejected');
      case ApprovalStatus.withdrawn:
        return l10n.get('statusWithdrawn');
    }
  }
}

class ApprovalRecord {
  final String id;
  final String bizId;
  final String bizType;
  final String approverId;
  final String approverName;
  final int approvalLevel;
  final String action;
  final String opinion;
  final DateTime approvalTime;

  const ApprovalRecord({
    required this.id,
    required this.bizId,
    required this.bizType,
    required this.approverId,
    required this.approverName,
    required this.approvalLevel,
    required this.action,
    required this.opinion,
    required this.approvalTime,
  });

  factory ApprovalRecord.fromJson(Map<String, dynamic> json) {
    return ApprovalRecord(
      id: json['id'] as String,
      bizId: json['bizId'] as String,
      bizType: json['bizType'] as String,
      approverId: json['approverId'] as String,
      approverName: json['approverName'] as String,
      approvalLevel: json['approvalLevel'] as int,
      action: json['action'] as String,
      opinion: json['opinion'] as String? ?? '',
      approvalTime: DateTime.parse(json['approvalTime'] as String),
    );
  }

  Map<String, dynamic> toJson() => {
    'id': id,
    'bizId': bizId,
    'bizType': bizType,
    'approverId': approverId,
    'approverName': approverName,
    'approvalLevel': approvalLevel,
    'action': action,
    'opinion': opinion,
    'approvalTime': approvalTime.toIso8601String(),
  };
}
