import 'package:hive_flutter/hive_flutter.dart';

part 'app_settings.g.dart';

/// User settings stored in Hive.
@HiveType(typeId: 0)
class AppSettings extends HiveObject {
  @HiveField(0)
  String userName;

  @HiveField(1)
  String userEmail;

  @HiveField(2)
  int themeModeIndex; // 0=system, 1=light, 2=dark

  @HiveField(3)
  double arabicFontSize;

  @HiveField(4)
  String uiLanguage; // 'id' or 'en'

  @HiveField(5)
  Map<String, bool> adhanEnabled;

  @HiveField(6)
  Map<String, int> iqamahOffset; // minutes

  @HiveField(7)
  String? checklistReminderTime; // HH:mm format

  @HiveField(8)
  double? lastLat;

  @HiveField(9)
  double? lastLng;

  @HiveField(10)
  String? lastCityName;

  @HiveField(11)
  int rawatibLevel; // 0 = Off, 1 = Muakkad Only, 2 = Full

  @HiveField(12)
  int tilawahTargetValue;

  @HiveField(13)
  String tilawahTargetUnit; // 'Juz', 'Halaman', 'Ayat'

  @HiveField(14)
  bool tilawahAutoSync;

  @HiveField(15)
  bool trackDzikir;

  @HiveField(16)
  bool trackPuasa;

  @HiveField(17)
  bool showLatin;

  @HiveField(18)
  bool showTerjemahan;

  @HiveField(19)
  bool simpleMode; // false = Mode Lengkap, true = Mode Simpel

  @HiveField(20)
  String dzikirDisplayMode; // 'list' | 'focus'

  @HiveField(21)
  String dzikirCounterButtonPosition; // 'bottomPill' | 'fabCircle'

  @HiveField(22)
  bool dzikirAutoAdvance;

  @HiveField(23)
  bool dzikirHapticOnCount;

  @HiveField(24)
  bool alertsEnabled;

  @HiveField(25)
  bool inboxEnabled;

  @HiveField(26)
  bool streakRiskEnabled;

  @HiveField(27)
  bool dailyChecklistReminderEnabled;

  @HiveField(28)
  bool weeklySummaryEnabled;

  @HiveField(29)
  String quietHoursStart; // HH:mm

  @HiveField(30)
  String quietHoursEnd; // HH:mm

  @HiveField(31)
  int maxNonPrayerPushPerDay;

  @HiveField(32)
  bool mirrorAdzanToInbox;

  @HiveField(33)
  bool tilawahAutoContinueNextSurah;

  @HiveField(34)
  bool shalatReportReminderEnabled;

  @HiveField(35)
  int shalatReportReminderDelayMinutes;

  @HiveField(36)
  int shalatReportReminderRepeatCount;

  @HiveField(37)
  int shalatReportReminderRepeatIntervalMinutes;

  AppSettings({
    this.userName = 'User',
    this.userEmail = '',
    this.themeModeIndex = 0,
    this.arabicFontSize = 24.0,
    this.uiLanguage = 'id',
    Map<String, bool>? adhanEnabled,
    Map<String, int>? iqamahOffset,
    this.checklistReminderTime = '09:00',
    this.lastLat,
    this.lastLng,
    this.lastCityName,
    this.rawatibLevel = 1, // Default to Muakkad
    this.tilawahTargetValue = 1,
    this.tilawahTargetUnit = 'Juz',
    this.tilawahAutoSync = false,
    this.trackDzikir = true,
    this.trackPuasa = false,
    this.showLatin = true,
    this.showTerjemahan = true,
    this.simpleMode = false,
    this.dzikirDisplayMode = 'list',
    this.dzikirCounterButtonPosition = 'bottomPill',
    this.dzikirAutoAdvance = true,
    this.dzikirHapticOnCount = true,
    this.alertsEnabled = true,
    this.inboxEnabled = true,
    this.streakRiskEnabled = true,
    this.dailyChecklistReminderEnabled = false,
    this.weeklySummaryEnabled = true,
    this.quietHoursStart = '22:00',
    this.quietHoursEnd = '05:00',
    this.maxNonPrayerPushPerDay = 2,
    this.mirrorAdzanToInbox = false,
    this.tilawahAutoContinueNextSurah = true,
    this.shalatReportReminderEnabled = true,
    this.shalatReportReminderDelayMinutes = 30,
    this.shalatReportReminderRepeatCount = 1,
    this.shalatReportReminderRepeatIntervalMinutes = 15,
  })  : adhanEnabled = adhanEnabled ??
            {
              'fajr': true,
              'dhuhr': true,
              'asr': true,
              'maghrib': true,
              'isha': true,
            },
        iqamahOffset = iqamahOffset ??
            {
              'fajr': 15,
              'dhuhr': 10,
              'asr': 10,
              'maghrib': 5,
              'isha': 10,
            };
}
