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

import '../file/fileSettings.dart';
import '../fileView/fileViewSettings.dart';
import '../gradeAverages/gradeAveragesSettings.dart';
import '../holidays/holidaysSettings.dart';
import '../notification/notificationSettings.dart';
import '../talk/talkSettings.dart';
import '../timetable/timetableSettings.dart';

part 'settings.g.dart';

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

  GradeAveragesSettings gradeAveragesSettings;
  TimetableSettings timetableSettings;
  TalkSettings talkSettings;
  FileSettings fileSettings;
  HolidaysSettings holidaysSettings;
  FileViewSettings fileViewSettings;
  NotificationSettings notificationSettings;

  Settings({
    required this.appTheme,
    required this.devToolsEnabled,
    required this.gradeAveragesSettings,
    required this.timetableSettings,
    required this.talkSettings,
    required this.fileSettings,
    required this.holidaysSettings,
    required this.fileViewSettings,
    required this.notificationSettings,
  });

  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);
}