import 'package:flutter/material.dart';
import 'package:geolocator/geolocator.dart';
import 'package:bookatanker/common/settings.dart';


class SuppliersModel {
  String supplier_name = '';
  String status='';
  String supplier_address='';
  String supplier_phone_number='';
  String supplier_id='';
  Color text_color=Colors.black;
  double lat=0;
  double lng=0;
  String distrubance_price='';
  String amount_difference='';
  double distanceInMeters=0;
  String displayAddress='';
  bool isFavorite=false;
  bool isRequetsedBooking=false;
  String? matchedPrice;

  SuppliersModel();

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

    rtvm.supplier_name = json['supplier']['suppliername'] ?? '';
    rtvm.status = json['supplier']['status'] ?? '';
    rtvm.supplier_address = json['supplier']['profile']['office_address'] ?? '';
    rtvm.supplier_phone_number =json['supplier']['phone'] ?? '';
    rtvm.supplier_id = json['supplier']['supplierId'] ?? '';
    rtvm.isFavorite = json['isFavorite'] ?? false;
    rtvm.isRequetsedBooking = json['requestedBooking']['status'] ?? false;
    rtvm.lat =  json['supplier']['latitude'] ?? 0;
    rtvm.lng =  json['supplier']['longitude'] ?? 0;
    List<String> parts = rtvm.supplier_address.split(',');
    rtvm.displayAddress = parts[2].trim();
    rtvm.distanceInMeters = double.parse((Geolocator.distanceBetween(
        rtvm.lat,
        rtvm.lng,
        AppSettings.userLatitude,
        AppSettings.userLongitude
    ) / 1000).toStringAsFixed(2));




    return rtvm;
  }

}