import 'dart:convert';

import 'package:flutter/material.dart';
import 'package:geolocator/geolocator.dart';
import 'package:bookatanker/common/settings.dart';
import 'dart:typed_data';
class favouritesModel {
  String supplier_name = '';
  String status='';
  String supplier_address='';
  String supplier_phone_number='';
  String supplier_alternate_phone_number='';
  String supplier_id='';
  String about_supplier='';
  String startingprice_supplier='';
  String supplier_image='';
  String distance='';
  String distanceInKm='';
  String bs64str='';
  String picture='';
  Map<String,dynamic> picture1={};
  Color text_color=Colors.black;
  double lat=0;
  double lng=0;
  var data;
  double distanceInMeters=0;
  String displayAddress='';
  bool isFavorite=false;
  //File? updatedImage;

  favouritesModel();

  factory favouritesModel.fromJson(Map<String, dynamic> json){
    favouritesModel rtvm = new favouritesModel();

    rtvm.supplier_name = json['suppliername'] ?? '';
    rtvm.status = json['status'] ?? '';
    rtvm.supplier_address = json['profile']['office_address'] ?? '';
    rtvm.supplier_phone_number = json['phone'] ?? '';
    rtvm.supplier_alternate_phone_number = json['alternativeContactNumber'] ?? '';
    rtvm.supplier_id = json['supplierId'] ?? '';
    rtvm.lat = json['latitude'] ?? 0;
    rtvm.lng = json['longitude'] ??0;
    rtvm.about_supplier = json['description'] ?? '';
    rtvm.startingprice_supplier = json['startingPrice'] ?? '';
    rtvm.picture = json['picture'] ?? '';
    rtvm.isFavorite = json['favorate'] ?? false;
    rtvm.distanceInMeters = double.parse((Geolocator.distanceBetween(
        rtvm.lat,
        rtvm.lng,
        AppSettings.userLatitude,
        AppSettings.userLongitude
    ) / 1000).toStringAsFixed(2));

    List<String> parts = rtvm.supplier_address.split(',');
    rtvm.displayAddress = parts[2].trim();



    if(rtvm.status.toString().toLowerCase()=='pending'){
      rtvm.text_color=Colors.yellow;
    }
    else if(rtvm.status.toString().toLowerCase()=='accepted'){
      rtvm.text_color=Colors.green;
    }
    else if(rtvm.status.toString().toLowerCase()=='rejected'){
      rtvm.text_color=Colors.red;
    }
    else{
      rtvm.status='Connect?';
      rtvm.text_color=primaryColor;
    }




    return rtvm;
  }

}