// 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 DemographicSupadartModel
    implements SupadartClass<DemographicSupadartModel> {
  final String id;
  final String districtId;
  final int population;
  final int numberOfUnemployed;
  final double populationDensity;
  final int year;
  final DateTime? createdAt;
  final DateTime? updatedAt;
  final DistrictSupadartModel? district;

  const DemographicSupadartModel({
    required this.id,
    required this.districtId,
    required this.population,
    required this.numberOfUnemployed,
    required this.populationDensity,
    required this.year,
    this.createdAt,
    this.updatedAt,
    this.district,
  });

  static String get table_name => 'demographicSupadartModel';
  static String get c_id => 'id';
  static String get c_districtId => 'district_id';
  static String get c_population => 'population';
  static String get c_numberOfUnemployed => 'number_of_unemployed';
  static String get c_populationDensity => 'population_density';
  static String get c_year => 'year';
  static String get c_createdAt => 'created_at';
  static String get c_updatedAt => 'updated_at';

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

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

  static Map<String, dynamic> _generateMap({
    String? id,
    String? districtId,
    int? population,
    int? numberOfUnemployed,
    double? populationDensity,
    int? year,
    DateTime? createdAt,
    DateTime? updatedAt,
  }) {
    return {
      if (id != null) 'id': id,
      if (districtId != null) 'district_id': districtId,
      if (population != null) 'population': population,
      if (numberOfUnemployed != null)
        'number_of_unemployed': numberOfUnemployed,
      if (populationDensity != null)
        'population_density': populationDensity.toString(),
      if (year != null) 'year': year,
      if (createdAt != null) 'created_at': createdAt.toUtc().toIso8601String(),
      if (updatedAt != null) 'updated_at': updatedAt.toUtc().toIso8601String(),
    };
  }

  static Map<String, dynamic> insert({
    String? id,
    required String districtId,
    required int population,
    required int numberOfUnemployed,
    required double populationDensity,
    required int year,
    DateTime? createdAt,
    DateTime? updatedAt,
  }) {
    return _generateMap(
      id: id,
      districtId: districtId,
      population: population,
      numberOfUnemployed: numberOfUnemployed,
      populationDensity: populationDensity,
      year: year,
      createdAt: createdAt,
      updatedAt: updatedAt,
    );
  }

  static Map<String, dynamic> update({
    String? id,
    String? districtId,
    int? population,
    int? numberOfUnemployed,
    double? populationDensity,
    int? year,
    DateTime? createdAt,
    DateTime? updatedAt,
  }) {
    return _generateMap(
      id: id,
      districtId: districtId,
      population: population,
      numberOfUnemployed: numberOfUnemployed,
      populationDensity: populationDensity,
      year: year,
      createdAt: createdAt,
      updatedAt: updatedAt,
    );
  }

  factory DemographicSupadartModel.fromJson(Map<String, dynamic> jsonn) {
    return DemographicSupadartModel(
      id: jsonn['id'] != null ? jsonn['id'].toString() : '',
      districtId:
          jsonn['district_id'] != null ? jsonn['district_id'].toString() : '',
      population:
          jsonn['population'] != null
              ? int.parse(jsonn['population'].toString())
              : 0,
      numberOfUnemployed:
          jsonn['number_of_unemployed'] != null
              ? int.parse(jsonn['number_of_unemployed'].toString())
              : 0,
      populationDensity:
          jsonn['population_density'] != null
              ? double.parse(jsonn['population_density'].toString())
              : 0.0,
      year: jsonn['year'] != null ? int.parse(jsonn['year'].toString()) : 0,
      createdAt:
          jsonn['created_at'] != null
              ? DateTime.parse(jsonn['created_at'].toString())
              : null,
      updatedAt:
          jsonn['updated_at'] != null
              ? DateTime.parse(jsonn['updated_at'].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,
      population: population,
      numberOfUnemployed: numberOfUnemployed,
      populationDensity: populationDensity,
      year: year,
      createdAt: createdAt,
      updatedAt: updatedAt,
      // 'districts': district?.toJson(),
    );
  }

  static const _unset = Object();
  DemographicSupadartModel copyWith({
    Object? id = _unset,
    Object? districtId = _unset,
    Object? population = _unset,
    Object? numberOfUnemployed = _unset,
    Object? populationDensity = _unset,
    Object? year = _unset,
    Object? createdAt = _unset,
    Object? updatedAt = _unset,
    Object? district = _unset,
  }) {
    return DemographicSupadartModel(
      id: id == _unset ? this.id : id as String,
      districtId: districtId == _unset ? this.districtId : districtId as String,
      population: population == _unset ? this.population : population as int,
      numberOfUnemployed:
          numberOfUnemployed == _unset
              ? this.numberOfUnemployed
              : numberOfUnemployed as int,
      populationDensity:
          populationDensity == _unset
              ? this.populationDensity
              : populationDensity as double,
      year: year == _unset ? this.year : year as int,
      createdAt: createdAt == _unset ? this.createdAt : createdAt as DateTime?,
      updatedAt: updatedAt == _unset ? this.updatedAt : updatedAt as DateTime?,
      district:
          district == _unset
              ? this.district
              : district as DistrictSupadartModel?,
    );
  }
}
