import 'package:flutter/material.dart';
import 'package:initial_folder/models/data_diri_model.dart';
import 'package:initial_folder/services/user_info_service.dart';

enum ResultStateData { Loading, NoData, HasData, Error }

class DataDiriProvider with ChangeNotifier {
  final UserInfoService userInfoService;

  DataDiriProvider({
    required this.userInfoService,
  }) {
    getDataDiri();
  }

  DataDiriModel? _dataDiriModel;

  ResultStateData? _state;

  String _message = '';

  DataDiriModel? get result => _dataDiriModel;

  ResultStateData? get state => _state;

  String get message => _message;

  bool _isNewBirthDate = false;
  bool get isNewBirthDate => _isNewBirthDate;

  bool _newName = false;
  bool get newName => _newName;

  bool _newHeadline = false;
  bool get newHeadline => _newHeadline;

  bool _newBiograpy = false;
  bool get newBiograpy => _newBiograpy;

  bool _newEmail = false;
  bool get newEmail => _newEmail;

  bool _newPhone = false;
  bool get newPhone => _newPhone;

  bool _newGender = false;
  bool get newGender => _newGender;

  bool _newInstagram = false;
  bool get newInstagram => _newInstagram;

  bool _newTwitter = false;
  bool get newTwitter => _newTwitter;

  bool _newFacebook = false;
  bool get newFacebook => _newFacebook;

  bool _newLinkedin = false;
  bool get newLinkedin => _newLinkedin;

  set isNewBirthDate(bool value) {
    _isNewBirthDate = value;
    notifyListeners();
  }

  set newName(bool value) {
    _newName = value;
    notifyListeners();
  }

  set newHeadline(bool value) {
    _newHeadline = value;
    notifyListeners();
  }

  set newBiograpy(bool value) {
    _newBiograpy = value;
    notifyListeners();
  }

  set newEmail(bool value) {
    _newEmail = value;
    notifyListeners();
  }

  set newPhone(bool value) {
    _newPhone = value;
    notifyListeners();
  }

  set newGender(bool value) {
    _newGender = value;
    notifyListeners();
  }

  set newInstagram(bool value) {
    _newInstagram = value;
    notifyListeners();
  }

  set newTwitter(bool value) {
    _newTwitter = value;
    notifyListeners();
  }

  set newFacebook(bool value) {
    _newFacebook = value;
    notifyListeners();
  }

  set newLinkedin(bool value) {
    _newLinkedin = value;
    notifyListeners();
  }

  set dataDiri(DataDiriModel dataDiri) {
    _dataDiriModel = dataDiri;
    notifyListeners();
  }

  Future<dynamic> getDataDiri() async {
    try {
      _state = ResultStateData.Loading;
      notifyListeners();
      DataDiriModel dataDiri = await userInfoService.getDataDiri();

      _state = ResultStateData.HasData;
      notifyListeners();
      _dataDiriModel = dataDiri;
      return _dataDiriModel;
    } catch (e) {
      _state = ResultStateData.Error;
      notifyListeners();
      return _message = 'Error --> $e';
    }
  }
}
