class ServiceModel {
  final int id;
  final int vendorId;
  final int serviceType;
  final String vendorName;
  final String serviceName;
  final int category;
  final int subcategory;
  final String workingHours;
  final String workingDuration;
  final String amount;
  final String location;
  final String description;
  final String details;

  final String? videos;
  final String createdDate;
  final String vendorDisplayName;

  final String? profilePic1; // Added for JSON field "profile_pic1"
  final String? averageReview;
  final String phoneNumber;
  final String categoryName;
  final String subcategoryName;
  final List<String>? images1; // Changed to List<String>?

  ServiceModel({
    required this.id,
    required this.vendorId,
    required this.serviceType,
    required this.vendorName,
    required this.serviceName,
    required this.category,
    required this.subcategory,
    required this.workingHours,
    required this.workingDuration,
    required this.amount,
    required this.location,
    required this.description,
    required this.details,

    this.videos,
    required this.createdDate,
    required this.vendorDisplayName,

    this.profilePic1,
    this.averageReview,
    required this.phoneNumber,
    required this.categoryName,
    required this.subcategoryName,
    this.images1,
  });

  factory ServiceModel.fromJson(Map<String, dynamic> json) {
    return ServiceModel(
      id: json['id'] ?? 0,
      vendorId: json['vendor_id'] ?? 0,
      serviceType: json['service_type'] ?? 0,
      vendorName: json['vendorname']?.toString() ?? '',
      serviceName: json['servicename']?.toString() ?? '',
      category: json['category'] ?? 0,
      subcategory: json['subcategory'] ?? 0,
      workingHours: json['workinghours']?.toString() ?? '',
      workingDuration: json['workingduration']?.toString() ?? '',
      amount: json['amount']?.toString() ?? '',
      location: json['location']?.toString() ?? '',
      description: json['description']?.toString() ?? '',
      details: json['details']?.toString() ?? '',

      videos:
          (json['videos']?.toString().isNotEmpty ?? false)
              ? json['videos'].toString()
              : null,
      createdDate: json['created_date']?.toString() ?? '',
      vendorDisplayName: json['vendor_name']?.toString() ?? '',

      profilePic1: json['profile_pic1']?.toString(), // New field
      averageReview:
          (json['average_review']?.toString().isNotEmpty ?? false)
              ? json['average_review'].toString()
              : null,
      phoneNumber: json['phone_number']?.toString() ?? '',
      categoryName: json['category_name']?.toString() ?? '',
      subcategoryName: json['subcategory_name']?.toString() ?? '',
      images1:
          json['images1'] != null ? List<String>.from(json['images1']) : null,
    );
  }

  Map<String, dynamic> toJson() {
    return {
      'id': id,
      'vendor_id': vendorId,
      'service_type': serviceType,
      'vendorname': vendorName,
      'servicename': serviceName,
      'category': category,
      'subcategory': subcategory,
      'workinghours': workingHours,
      'workingduration': workingDuration,
      'amount': amount,
      'location': location,
      'description': description,
      'details': details,

      'videos': videos,
      'created_date': createdDate,
      'vendor_name': vendorDisplayName,

      'profile_pic1': profilePic1,
      'average_review': averageReview,
      'phone_number': phoneNumber,
      'category_name': categoryName,
      'subcategory_name': subcategoryName,
      'images1': images1,
    };
  }
}
