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

import '../../constants/constants.dart';

class LocalSource {
  final Box<dynamic> box;

  LocalSource(this.box);

  Future<void> clear() async {
    await box.clear();
  }

  Future<void> setLocale(String locale) async {
    await box.put(AppKeys.locale, locale);
  }

  String getLocale() {
    return box.get(AppKeys.locale, defaultValue: "uz") ?? "uz";
  }

  void setAccessToken(String accessToken) {
    box.put(AppKeys.accessToken, accessToken);
  }

  String? getAccessToken() {
    return box.get(AppKeys.accessToken);
  }

  void setFirstName(String firstName) {
    box.put(AppKeys.firstName, firstName);
  }

  String? getFirstName() {
    return box.get(AppKeys.firstName);
  }

  void setLastName(String lastName) {
    box.put(AppKeys.lastName, lastName);
  }

  String? getLastName() {
    return box.get(AppKeys.lastName);
  }

  void setEmail(String email) {
    box.put(AppKeys.email, email);
  }

  String? getEmail() {
    return box.get(AppKeys.email);
  }

  void setIsFirstEnter(bool isFirst) {
    box.put(AppKeys.isFirst, isFirst);
  }

  bool getIsFirstEnter() {
    return box.get(AppKeys.isFirst) ?? true;
  }

  void setUserId(String id) {
    box.put(AppKeys.userId, id);
  }

  String getUserId() {
    return box.get(AppKeys.userId) ?? "";
  }

  void setDateOfBirth(String id) {
    box.put(AppKeys.dateOfBirth, id);
  }

  String getDateOfBirth() {
    return box.get(AppKeys.dateOfBirth) ?? "";
  }

  void setRefreshToken(String id) {
    box.put(AppKeys.refreshToken, id);
  }

  String getRefreshToken() {
    return box.get(AppKeys.refreshToken) ?? "";
  }

  void setPhone(String id) {
    box.put(AppKeys.phone, id);
  }

  String getPhone() {
    return box.get(AppKeys.phone) ?? "";
  }

  void setHasProfile(bool id) {
    box.put(AppKeys.hasProfile, id);
  }

  bool getHasProfile() {
    return box.get(AppKeys.hasProfile) ?? false;
  }

  void setGender(String id) {
    box.put(AppKeys.gender, id);
  }

  String getGender() {
    return box.get(AppKeys.gender) ?? "";
  }

  void setIsProd(bool isProd) {
    box.put(AppKeys.isProd, isProd);
  }

  bool getIsProd() {
    return box.get(AppKeys.isProd) ?? true;
  }

  void setThemeMode(String mode) {
    box.put(AppKeys.themeMode, mode);
  }

  String getThemeMode() {
    return box.get(AppKeys.themeMode) ?? ThemeMode.light.name;
  }

  void setUCode(String mode) {
    box.put(AppKeys.ucode, mode);
  }

  String getUCode() {
    return box.get(AppKeys.ucode) ?? "";
  }
}
