// 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 GeographicSupadartModel
    implements SupadartClass<GeographicSupadartModel> {
  final String id;
  final String districtId;
  final String? address;
  final double longitude;
  final double latitude;
  final double? landArea;
  final String? polygon;
  final String? geometry;
  final DateTime? createdAt;
  final DateTime? updatedAt;
  final String? description;
  final String? type;
  final String location;
  final int? year;
  final DistrictSupadartModel? district;

  const GeographicSupadartModel({
    required this.id,
    required this.districtId,
    this.address,
    required this.longitude,
    required this.latitude,
    this.landArea,
    this.polygon,
    this.geometry,
    this.createdAt,
    this.updatedAt,
    this.description,
    this.type,
    required this.location,
    this.year,
    this.district,
  });

  static String get table_name => 'geographicSupadartModel';
  static String get c_id => 'id';
  static String get c_districtId => 'district_id';
  static String get c_address => 'address';
  static String get c_longitude => 'longitude';
  static String get c_latitude => 'latitude';
  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_description => 'description';
  static String get c_type => 'type';
  static String get c_location => 'location';
  static String get c_year => 'year';

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

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

  static Map<String, dynamic> _generateMap({
    String? id,
    String? districtId,
    String? address,
    double? longitude,
    double? latitude,
    double? landArea,
    String? polygon,
    String? geometry,
    DateTime? createdAt,
    DateTime? updatedAt,
    String? description,
    String? type,
    String? location,
    int? year,
  }) {
    return {
      if (id != null) 'id': id,
      if (districtId != null) 'district_id': districtId,
      if (address != null) 'address': address,
      if (longitude != null) 'longitude': longitude.toString(),
      if (latitude != null) 'latitude': latitude.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 (description != null) 'description': description,
      if (type != null) 'type': type,
      if (location != null) 'location': location,
      if (year != null) 'year': year,
    };
  }

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

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

  factory GeographicSupadartModel.fromJson(Map<String, dynamic> jsonn) {
    return GeographicSupadartModel(
      id: jsonn['id'] != null ? jsonn['id'].toString() : '',
      districtId:
          jsonn['district_id'] != null ? jsonn['district_id'].toString() : '',
      address: jsonn['address'] != null ? jsonn['address'].toString() : null,
      longitude:
          jsonn['longitude'] != null
              ? double.parse(jsonn['longitude'].toString())
              : 0.0,
      latitude:
          jsonn['latitude'] != null
              ? double.parse(jsonn['latitude'].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,
      description:
          jsonn['description'] != null ? jsonn['description'].toString() : null,
      type: jsonn['type'] != null ? jsonn['type'].toString() : null,
      location: jsonn['location'] != null ? jsonn['location'].toString() : '',
      year: jsonn['year'] != null ? int.parse(jsonn['year'].toString()) : null,
      district:
          jsonn['districts'] != null
              ? DistrictSupadartModel.fromJson(
                jsonn['districts'] as Map<String, dynamic>,
              )
              : null,
    );
  }

  Map<String, dynamic> toJson() {
    return _generateMap(
      id: id,
      districtId: districtId,
      address: address,
      longitude: longitude,
      latitude: latitude,
      landArea: landArea,
      polygon: polygon,
      geometry: geometry,
      createdAt: createdAt,
      updatedAt: updatedAt,
      description: description,
      type: type,
      location: location,
      year: year,
    );
  }

  static const _unset = Object();
  GeographicSupadartModel copyWith({
    Object? id = _unset,
    Object? districtId = _unset,
    Object? address = _unset,
    Object? longitude = _unset,
    Object? latitude = _unset,
    Object? landArea = _unset,
    Object? polygon = _unset,
    Object? geometry = _unset,
    Object? createdAt = _unset,
    Object? updatedAt = _unset,
    Object? description = _unset,
    Object? type = _unset,
    Object? location = _unset,
    Object? year = _unset,
    Object? district = _unset,
  }) {
    return GeographicSupadartModel(
      id: id == _unset ? this.id : id as String,
      districtId: districtId == _unset ? this.districtId : districtId as String,
      address: address == _unset ? this.address : address as String?,
      longitude: longitude == _unset ? this.longitude : longitude as double,
      latitude: latitude == _unset ? this.latitude : latitude 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?,
      description:
          description == _unset ? this.description : description as String?,
      type: type == _unset ? this.type : type as String?,
      location: location == _unset ? this.location : location as String,
      year: year == _unset ? this.year : year as int?,
      district:
          district == _unset
              ? this.district
              : district as DistrictSupadartModel?,
    );
  }
}
