// 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';

enum CRIME_RATES { critical, high, low, medium }

class CrimeSupadartModel implements SupadartClass<CrimeSupadartModel> {
  final String id;
  final String districtId;
  final DateTime? createdAt;
  final CRIME_RATES level;
  final String? method;
  final int? month;
  final int numberOfCrime;
  final double score;
  final DateTime? updatedAt;
  final int? year;
  final String? sourceType;
  final int crimeCleared;
  final double avgCrime;
  final DistrictSupadartModel? district;

  const CrimeSupadartModel({
    required this.id,
    required this.districtId,
    this.createdAt,
    required this.level,
    this.method,
    this.month,
    required this.numberOfCrime,
    required this.score,
    this.updatedAt,
    this.year,
    this.sourceType,
    required this.crimeCleared,
    required this.avgCrime,
    this.district,
  });

  static String get table_name => 'crimeSupadartModel';
  static String get c_id => 'id';
  static String get c_districtId => 'district_id';
  static String get c_createdAt => 'created_at';
  static String get c_level => 'level';
  static String get c_method => 'method';
  static String get c_month => 'month';
  static String get c_numberOfCrime => 'number_of_crime';
  static String get c_score => 'score';
  static String get c_updatedAt => 'updated_at';
  static String get c_year => 'year';
  static String get c_sourceType => 'source_type';
  static String get c_crimeCleared => 'crime_cleared';
  static String get c_avgCrime => 'avg_crime';

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

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

  static Map<String, dynamic> _generateMap({
    String? id,
    String? districtId,
    DateTime? createdAt,
    CRIME_RATES? level,
    String? method,
    int? month,
    int? numberOfCrime,
    double? score,
    DateTime? updatedAt,
    int? year,
    String? sourceType,
    int? crimeCleared,
    double? avgCrime,
  }) {
    return {
      if (id != null) 'id': id,
      if (districtId != null) 'district_id': districtId,
      if (createdAt != null) 'created_at': createdAt.toUtc().toIso8601String(),
      if (level != null) 'level': level.toString().split('.').last,
      if (method != null) 'method': method,
      if (month != null) 'month': month,
      if (numberOfCrime != null) 'number_of_crime': numberOfCrime,
      if (score != null) 'score': score.toString(),
      if (updatedAt != null) 'updated_at': updatedAt.toUtc().toIso8601String(),
      if (year != null) 'year': year,
      if (sourceType != null) 'source_type': sourceType,
      if (crimeCleared != null) 'crime_cleared': crimeCleared,
      if (avgCrime != null) 'avg_crime': avgCrime.toString(),
    };
  }

  static Map<String, dynamic> insert({
    String? id,
    required String districtId,
    DateTime? createdAt,
    CRIME_RATES? level,
    String? method,
    int? month,
    int? numberOfCrime,
    double? score,
    DateTime? updatedAt,
    int? year,
    String? sourceType,
    int? crimeCleared,
    double? avgCrime,
  }) {
    return _generateMap(
      id: id,
      districtId: districtId,
      createdAt: createdAt,
      level: level,
      method: method,
      month: month,
      numberOfCrime: numberOfCrime,
      score: score,
      updatedAt: updatedAt,
      year: year,
      sourceType: sourceType,
      crimeCleared: crimeCleared,
      avgCrime: avgCrime,
    );
  }

  static Map<String, dynamic> update({
    String? id,
    String? districtId,
    DateTime? createdAt,
    CRIME_RATES? level,
    String? method,
    int? month,
    int? numberOfCrime,
    double? score,
    DateTime? updatedAt,
    int? year,
    String? sourceType,
    int? crimeCleared,
    double? avgCrime,
  }) {
    return _generateMap(
      id: id,
      districtId: districtId,
      createdAt: createdAt,
      level: level,
      method: method,
      month: month,
      numberOfCrime: numberOfCrime,
      score: score,
      updatedAt: updatedAt,
      year: year,
      sourceType: sourceType,
      crimeCleared: crimeCleared,
      avgCrime: avgCrime,
    );
  }

  factory CrimeSupadartModel.fromJson(Map<String, dynamic> jsonn) {
    return CrimeSupadartModel(
      id: jsonn['id'] != null ? jsonn['id'].toString() : '',
      districtId:
          jsonn['district_id'] != null ? jsonn['district_id'].toString() : '',
      createdAt:
          jsonn['created_at'] != null
              ? DateTime.parse(jsonn['created_at'].toString())
              : null,
      level:
          jsonn['level'] != null
              ? CRIME_RATES.values.byName(jsonn['level'].toString())
              : CRIME_RATES.values.first,
      method: jsonn['method'] != null ? jsonn['method'].toString() : null,
      month:
          jsonn['month'] != null ? int.parse(jsonn['month'].toString()) : null,
      numberOfCrime:
          jsonn['number_of_crime'] != null
              ? int.parse(jsonn['number_of_crime'].toString())
              : 0,
      score:
          jsonn['score'] != null
              ? double.parse(jsonn['score'].toString())
              : 0.0,
      updatedAt:
          jsonn['updated_at'] != null
              ? DateTime.parse(jsonn['updated_at'].toString())
              : null,
      year: jsonn['year'] != null ? int.parse(jsonn['year'].toString()) : null,
      sourceType:
          jsonn['source_type'] != null ? jsonn['source_type'].toString() : null,
      crimeCleared:
          jsonn['crime_cleared'] != null
              ? int.parse(jsonn['crime_cleared'].toString())
              : 0,
      avgCrime:
          jsonn['avg_crime'] != null
              ? double.parse(jsonn['avg_crime'].toString())
              : 0.0,
      district:
          jsonn['districts'] != null
              ? DistrictSupadartModel.fromJson(
                jsonn['districts'] as Map<String, dynamic>,
              )
              : null,
    );
  }

  Map<String, dynamic> toJson() {
    return _generateMap(
      id: id,
      districtId: districtId,
      createdAt: createdAt,
      level: level,
      method: method,
      month: month,
      numberOfCrime: numberOfCrime,
      score: score,
      updatedAt: updatedAt,
      year: year,
      sourceType: sourceType,
      crimeCleared: crimeCleared,
      avgCrime: avgCrime,
      // 'districts': district?.toJson(),
    );
  }

  static const _unset = Object();
  CrimeSupadartModel copyWith({
    Object? id = _unset,
    Object? districtId = _unset,
    Object? createdAt = _unset,
    Object? level = _unset,
    Object? method = _unset,
    Object? month = _unset,
    Object? numberOfCrime = _unset,
    Object? score = _unset,
    Object? updatedAt = _unset,
    Object? year = _unset,
    Object? sourceType = _unset,
    Object? crimeCleared = _unset,
    Object? avgCrime = _unset,
    Object? district = _unset,
  }) {
    return CrimeSupadartModel(
      id: id == _unset ? this.id : id as String,
      districtId: districtId == _unset ? this.districtId : districtId as String,
      createdAt: createdAt == _unset ? this.createdAt : createdAt as DateTime?,
      level: level == _unset ? this.level : level as CRIME_RATES,
      method: method == _unset ? this.method : method as String?,
      month: month == _unset ? this.month : month as int?,
      numberOfCrime:
          numberOfCrime == _unset ? this.numberOfCrime : numberOfCrime as int,
      score: score == _unset ? this.score : score as double,
      updatedAt: updatedAt == _unset ? this.updatedAt : updatedAt as DateTime?,
      year: year == _unset ? this.year : year as int?,
      sourceType:
          sourceType == _unset ? this.sourceType : sourceType as String?,
      crimeCleared:
          crimeCleared == _unset ? this.crimeCleared : crimeCleared as int,
      avgCrime: avgCrime == _unset ? this.avgCrime : avgCrime as double,
      district:
          district == _unset
              ? this.district
              : district as DistrictSupadartModel?,
    );
  }
}
