import 'package:cloud_firestore/cloud_firestore.dart';

class SettingModel {
  final bool domicilios;
  final bool tarifas;
  final String titulo;
  final String parrafo;
  final String numero;
  final String email;
  final String dias;
  final String horas;
  final String version;
  final String proliticasPrivacidad;
  final String terminosCondiciones;

  SettingModel(
    this.domicilios,
    this.tarifas,
    this.titulo,
    this.parrafo,
    this.numero,
    this.email,
    this.dias,
    this.horas,
    this.version,
    this.proliticasPrivacidad,
    this.terminosCondiciones,
  );

  static Future<SettingModel> fromJson(Map<String, dynamic> json) async {
    try {
      if (json == null)
        return SettingModel(false, false, '', '', '', '', '', '', '', '', '');

      return SettingModel(
        json['domicilio'],
        json['tarifa'],
        json['titulo_soporte'],
        json['parrafo_soporte'],
        json['numero_soporte'],
        json['email_soporte'],
        json['dias_soporte'],
        json['horas_soporte'],
        json['version'],
        json['politicas_privacidad'],
        json['terminos_condiciones'],
      );
    } catch (e) {
      print('Error settings: $e');
      return SettingModel(false, false, '', '', '', '', '', '', '', '', '');
    }
  }

  static Future<SettingModel> getSettings() async {
    try {
      final DocumentSnapshot<Map<String, dynamic>> snapshot =
          await FirebaseFirestore.instance
              .collection('settings')
              .doc('global')
              .get();

      final Map<String, dynamic>? data = snapshot.data();

      return fromJson(data!);
    } catch (e) {
      print('Error getting settings: $e');
      return SettingModel(false, false, '', '', '', '', '', '', '', '', '');
    }
  }
}
