import 'package:flutter/material.dart';
import 'package:json_annotation/json_annotation.dart';

import 'chat_background_settings.dart';
import 'dev_tools_settings.dart';
import 'file_settings.dart';
import 'file_view_settings.dart';
import 'haptic_settings.dart';
import 'holidays_settings.dart';
import 'modules_settings.dart';
import 'notification_settings.dart';
import 'talk_settings.dart';
import 'timetable_favorites_settings.dart';
import 'timetable_settings.dart';

part 'settings.g.dart';

@JsonSerializable(explicitToJson: true)
class Settings {
  @JsonKey(toJson: _themeToJson, fromJson: _themeFromJson)
  ThemeMode appTheme;
  bool devToolsEnabled;

  ModulesSettings modulesSettings;
  TimetableSettings timetableSettings;
  TimetableFavoritesSettings timetableFavoritesSettings;
  TalkSettings talkSettings;
  ChatBackgroundSettings chatBackgroundSettings;
  FileSettings fileSettings;
  HolidaysSettings holidaysSettings;
  FileViewSettings fileViewSettings;
  NotificationSettings notificationSettings;
  DevToolsSettings devToolsSettings;
  HapticSettings hapticSettings;

  Settings({
    required this.appTheme,
    required this.devToolsEnabled,
    required this.modulesSettings,
    required this.timetableSettings,
    required this.timetableFavoritesSettings,
    required this.talkSettings,
    required this.chatBackgroundSettings,
    required this.fileSettings,
    required this.holidaysSettings,
    required this.fileViewSettings,
    required this.notificationSettings,
    required this.devToolsSettings,
    required this.hapticSettings,
  });

  static String _themeToJson(ThemeMode m) => m.name;
  static ThemeMode _themeFromJson(String m) =>
      ThemeMode.values.firstWhere((element) => element.name == m);

  factory Settings.fromJson(Map<String, dynamic> json) =>
      _$SettingsFromJson(json);
  Map<String, dynamic> toJson() => _$SettingsToJson(this);
}
