import 'package:meta/meta.dart';
import 'package:satu/core/models/settings/printer_setting.dart';

@immutable
class SettingState {

  factory SettingState.fromMap(dynamic map) {
    if (map == null) return SettingState.initial(null);
    return SettingState(
      printer: map['printer'] != null
          ? PrinterSetting.fromMap(map['printer'])
          : null,
    );
  }
  const SettingState({this.printer});

  factory SettingState.initial(SettingState? settingState) =>
      SettingState(printer: settingState?.printer ?? PrinterSetting());

  final PrinterSetting? printer;

  SettingState copyWith({PrinterSetting? printer}) {
    return SettingState(printer: printer ?? this.printer);
  }

  dynamic toMap() {
    return {
      'printer': printer !=null ? printer!.toMap() : null,
    };
  }
}
