// ignore_for_file: non_constant_identifier_names, camel_case_types, file_namesimport, file_names, unnecessary_null_comparison, prefer_null_aware_operators
// WARNING: This code is auto-generated by Supadart.
// WARNING: Modifications may be overwritten. Please make changes in the Supadart configuration.
import 'package:sigap/supadart/supadart_exports.dart';
import 'package:sigap/supadart/supadart_header.dart';

class LocationSupadartModel implements SupadartClass<LocationSupadartModel> {
  final String id;
  final String districtId;
  final String eventId;
  final String? address;
  final String? type;
  final double latitude;
  final double longitude;
  final double? landArea;
  final String? polygon;
  final String? geometry;
  final DateTime? createdAt;
  final DateTime? updatedAt;
  final String location;
  final double? distanceToUnit;
  final DistrictSupadartModel? district;
  final EventSupadartModel? event;

  const LocationSupadartModel({
    required this.id,
    required this.districtId,
    required this.eventId,
    this.address,
    this.type,
    required this.latitude,
    required this.longitude,
    this.landArea,
    this.polygon,
    this.geometry,
    this.createdAt,
    this.updatedAt,
    required this.location,
    this.distanceToUnit,
    this.district,
    this.event,
  });

  static String get table_name => 'locationSupadartModel';
  static String get c_id => 'id';
  static String get c_districtId => 'district_id';
  static String get c_eventId => 'event_id';
  static String get c_address => 'address';
  static String get c_type => 'type';
  static String get c_latitude => 'latitude';
  static String get c_longitude => 'longitude';
  static String get c_landArea => 'land_area';
  static String get c_polygon => 'polygon';
  static String get c_geometry => 'geometry';
  static String get c_createdAt => 'created_at';
  static String get c_updatedAt => 'updated_at';
  static String get c_location => 'location';
  static String get c_distanceToUnit => 'distance_to_unit';

  static List<LocationSupadartModel> converter(
    List<Map<String, dynamic>> data,
  ) {
    return data.map(LocationSupadartModel.fromJson).toList();
  }

  static LocationSupadartModel converterSingle(Map<String, dynamic> data) {
    return LocationSupadartModel.fromJson(data);
  }

  static Map<String, dynamic> _generateMap({
    String? id,
    String? districtId,
    String? eventId,
    String? address,
    String? type,
    double? latitude,
    double? longitude,
    double? landArea,
    String? polygon,
    String? geometry,
    DateTime? createdAt,
    DateTime? updatedAt,
    String? location,
    double? distanceToUnit,
  }) {
    return {
      if (id != null) 'id': id,
      if (districtId != null) 'district_id': districtId,
      if (eventId != null) 'event_id': eventId,
      if (address != null) 'address': address,
      if (type != null) 'type': type,
      if (latitude != null) 'latitude': latitude.toString(),
      if (longitude != null) 'longitude': longitude.toString(),
      if (landArea != null) 'land_area': landArea.toString(),
      if (polygon != null) 'polygon': polygon,
      if (geometry != null) 'geometry': geometry,
      if (createdAt != null) 'created_at': createdAt.toUtc().toIso8601String(),
      if (updatedAt != null) 'updated_at': updatedAt.toUtc().toIso8601String(),
      if (location != null) 'location': location,
      if (distanceToUnit != null) 'distance_to_unit': distanceToUnit.toString(),
    };
  }

  static Map<String, dynamic> insert({
    String? id,
    required String districtId,
    required String eventId,
    String? address,
    String? type,
    required double latitude,
    required double longitude,
    double? landArea,
    String? polygon,
    String? geometry,
    DateTime? createdAt,
    DateTime? updatedAt,
    required String location,
    double? distanceToUnit,
  }) {
    return _generateMap(
      id: id,
      districtId: districtId,
      eventId: eventId,
      address: address,
      type: type,
      latitude: latitude,
      longitude: longitude,
      landArea: landArea,
      polygon: polygon,
      geometry: geometry,
      createdAt: createdAt,
      updatedAt: updatedAt,
      location: location,
      distanceToUnit: distanceToUnit,
    );
  }

  static Map<String, dynamic> update({
    String? id,
    String? districtId,
    String? eventId,
    String? address,
    String? type,
    double? latitude,
    double? longitude,
    double? landArea,
    String? polygon,
    String? geometry,
    DateTime? createdAt,
    DateTime? updatedAt,
    String? location,
    double? distanceToUnit,
  }) {
    return _generateMap(
      id: id,
      districtId: districtId,
      eventId: eventId,
      address: address,
      type: type,
      latitude: latitude,
      longitude: longitude,
      landArea: landArea,
      polygon: polygon,
      geometry: geometry,
      createdAt: createdAt,
      updatedAt: updatedAt,
      location: location,
      distanceToUnit: distanceToUnit,
    );
  }

  factory LocationSupadartModel.fromJson(Map<String, dynamic> jsonn) {
    return LocationSupadartModel(
      id: jsonn['id'] != null ? jsonn['id'].toString() : '',
      districtId:
          jsonn['district_id'] != null ? jsonn['district_id'].toString() : '',
      eventId: jsonn['event_id'] != null ? jsonn['event_id'].toString() : '',
      address: jsonn['address'] != null ? jsonn['address'].toString() : null,
      type: jsonn['type'] != null ? jsonn['type'].toString() : null,
      latitude:
          jsonn['latitude'] != null
              ? double.parse(jsonn['latitude'].toString())
              : 0.0,
      longitude:
          jsonn['longitude'] != null
              ? double.parse(jsonn['longitude'].toString())
              : 0.0,
      landArea:
          jsonn['land_area'] != null
              ? double.parse(jsonn['land_area'].toString())
              : null,
      polygon: jsonn['polygon'] != null ? jsonn['polygon'].toString() : null,
      geometry: jsonn['geometry'] != null ? jsonn['geometry'].toString() : null,
      createdAt:
          jsonn['created_at'] != null
              ? DateTime.parse(jsonn['created_at'].toString())
              : null,
      updatedAt:
          jsonn['updated_at'] != null
              ? DateTime.parse(jsonn['updated_at'].toString())
              : null,
      location: jsonn['location'] != null ? jsonn['location'].toString() : '',
      distanceToUnit:
          jsonn['distance_to_unit'] != null
              ? double.parse(jsonn['distance_to_unit'].toString())
              : null,
      district:
          jsonn['districts'] != null
              ? DistrictSupadartModel.fromJson(
                jsonn['districts'] as Map<String, dynamic>,
              )
              : null,
      event:
          jsonn['events'] != null
              ? EventSupadartModel.fromJson(
                jsonn['events'] as Map<String, dynamic>,
              )
              : null,
    );
  }

  Map<String, dynamic> toJson() {
    return _generateMap(
      id: id,
      districtId: districtId,
      eventId: eventId,
      address: address,
      type: type,
      latitude: latitude,
      longitude: longitude,
      landArea: landArea,
      polygon: polygon,
      geometry: geometry,
      createdAt: createdAt,
      updatedAt: updatedAt,
      location: location,
      distanceToUnit: distanceToUnit,
      // 'districts': district?.toJson(),
      // 'events': event?.toJson(),
    );
  }

  static const _unset = Object();
  LocationSupadartModel copyWith({
    Object? id = _unset,
    Object? districtId = _unset,
    Object? eventId = _unset,
    Object? address = _unset,
    Object? type = _unset,
    Object? latitude = _unset,
    Object? longitude = _unset,
    Object? landArea = _unset,
    Object? polygon = _unset,
    Object? geometry = _unset,
    Object? createdAt = _unset,
    Object? updatedAt = _unset,
    Object? location = _unset,
    Object? distanceToUnit = _unset,
    Object? district = _unset,
    Object? event = _unset,
  }) {
    return LocationSupadartModel(
      id: id == _unset ? this.id : id as String,
      districtId: districtId == _unset ? this.districtId : districtId as String,
      eventId: eventId == _unset ? this.eventId : eventId as String,
      address: address == _unset ? this.address : address as String?,
      type: type == _unset ? this.type : type as String?,
      latitude: latitude == _unset ? this.latitude : latitude as double,
      longitude: longitude == _unset ? this.longitude : longitude as double,
      landArea: landArea == _unset ? this.landArea : landArea as double?,
      polygon: polygon == _unset ? this.polygon : polygon as String?,
      geometry: geometry == _unset ? this.geometry : geometry as String?,
      createdAt: createdAt == _unset ? this.createdAt : createdAt as DateTime?,
      updatedAt: updatedAt == _unset ? this.updatedAt : updatedAt as DateTime?,
      location: location == _unset ? this.location : location as String,
      distanceToUnit:
          distanceToUnit == _unset
              ? this.distanceToUnit
              : distanceToUnit as double?,
      district:
          district == _unset
              ? this.district
              : district as DistrictSupadartModel?,
      event: event == _unset ? this.event : event as EventSupadartModel?,
    );
  }
}
