// 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_STATUS { closed, open, resolved, underInvestigation, unresolved }

class CrimeIncidentSupadartModel
    implements SupadartClass<CrimeIncidentSupadartModel> {
  final String id;
  final String crimeId;
  final String crimeCategoryId;
  final String locationId;
  final String description;
  final int victimCount;
  final CRIME_STATUS? status;
  final DateTime? createdAt;
  final DateTime? updatedAt;
  final DateTime timestamp;

  final CrimeCategorySupadartModel? crimeCategory;
  final CrimeSupadartModel? crime;
  final LocationSupadartModel? location;

  const CrimeIncidentSupadartModel({
    required this.id,
    required this.crimeId,
    required this.crimeCategoryId,
    required this.locationId,
    required this.description,
    required this.victimCount,
    this.status,
    this.createdAt,
    this.updatedAt,
    required this.timestamp,
    this.crimeCategory,
    this.crime,
    this.location,
  });

  static String get table_name => 'crime_incidents';
  static String get c_id => 'id';
  static String get c_crimeId => 'crime_id';
  static String get c_crimeCategoryId => 'crime_category_id';
  static String get c_locationId => 'location_id';
  static String get c_description => 'description';
  static String get c_victimCount => 'victim_count';
  static String get c_status => 'status';
  static String get c_createdAt => 'created_at';
  static String get c_updatedAt => 'updated_at';
  static String get c_timestamp => 'timestamp';

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

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

  static Map<String, dynamic> _generateMap({
    String? id,
    String? crimeId,
    String? crimeCategoryId,
    String? locationId,
    String? description,
    int? victimCount,
    CRIME_STATUS? status,
    DateTime? createdAt,
    DateTime? updatedAt,
    DateTime? timestamp,
  }) {
    return {
      if (id != null) 'id': id,
      if (crimeId != null) 'crime_id': crimeId,
      if (crimeCategoryId != null) 'crime_category_id': crimeCategoryId,
      if (locationId != null) 'location_id': locationId,
      if (description != null) 'description': description,
      if (victimCount != null) 'victim_count': victimCount,
      if (status != null) 'status': status.toString().split('.').last,
      if (createdAt != null) 'created_at': createdAt.toUtc().toIso8601String(),
      if (updatedAt != null) 'updated_at': updatedAt.toUtc().toIso8601String(),
      if (timestamp != null) 'timestamp': timestamp.toUtc().toIso8601String(),
    };
  }

  static Map<String, dynamic> insert({
    String? id,
    required String crimeId,
    required String crimeCategoryId,
    required String locationId,
    required String description,
    required int victimCount,
    CRIME_STATUS? status,
    DateTime? createdAt,
    DateTime? updatedAt,
    required DateTime timestamp,
  }) {
    return _generateMap(
      id: id,
      crimeId: crimeId,
      crimeCategoryId: crimeCategoryId,
      locationId: locationId,
      description: description,
      victimCount: victimCount,
      status: status,
      createdAt: createdAt,
      updatedAt: updatedAt,
      timestamp: timestamp,
    );
  }

  static Map<String, dynamic> update({
    String? id,
    String? crimeId,
    String? crimeCategoryId,
    String? locationId,
    String? description,
    int? victimCount,
    CRIME_STATUS? status,
    DateTime? createdAt,
    DateTime? updatedAt,
    DateTime? timestamp,
  }) {
    return _generateMap(
      id: id,
      crimeId: crimeId,
      crimeCategoryId: crimeCategoryId,
      locationId: locationId,
      description: description,
      victimCount: victimCount,
      status: status,
      createdAt: createdAt,
      updatedAt: updatedAt,
      timestamp: timestamp,
    );
  }

  factory CrimeIncidentSupadartModel.fromJson(Map<String, dynamic> jsonn) {
    return CrimeIncidentSupadartModel(
      id: jsonn['id'] != null ? jsonn['id'].toString() : '',
      crimeId: jsonn['crime_id'] != null ? jsonn['crime_id'].toString() : '',
      crimeCategoryId:
          jsonn['crime_category_id'] != null
              ? jsonn['crime_category_id'].toString()
              : '',
      locationId:
          jsonn['location_id'] != null ? jsonn['location_id'].toString() : '',
      description:
          jsonn['description'] != null ? jsonn['description'].toString() : '',
      victimCount:
          jsonn['victim_count'] != null
              ? int.parse(jsonn['victim_count'].toString())
              : 0,
      status:
          jsonn['status'] != null
              ? CRIME_STATUS.values.byName(jsonn['status'].toString())
              : CRIME_STATUS.values.first,
      createdAt:
          jsonn['created_at'] != null
              ? DateTime.parse(jsonn['created_at'].toString())
              : null,
      updatedAt:
          jsonn['updated_at'] != null
              ? DateTime.parse(jsonn['updated_at'].toString())
              : null,
      timestamp:
          jsonn['timestamp'] != null
              ? DateTime.parse(jsonn['timestamp'].toString())
              : DateTime.fromMillisecondsSinceEpoch(0),
      crimeCategory:
          jsonn['crime_categories'] != null
              ? CrimeCategorySupadartModel.fromJson(
                jsonn['crime_categories'] as Map<String, dynamic>,
              )
              : null,
      crime:
          jsonn['crimes'] != null
              ? CrimeSupadartModel.fromJson(
                jsonn['crimes'] as Map<String, dynamic>,
              )
              : null,
      location:
          jsonn['locations'] != null
              ? LocationSupadartModel.fromJson(
                jsonn['locations'] as Map<String, dynamic>,
              )
              : null,
    );
  }

  Map<String, dynamic> toJson() {
    return _generateMap(
      id: id,
      crimeId: crimeId,
      crimeCategoryId: crimeCategoryId,
      locationId: locationId,
      description: description,
      victimCount: victimCount,
      status: status,
      createdAt: createdAt,
      updatedAt: updatedAt,
      timestamp: timestamp,
    );
  }

  static const _unset = Object();
  CrimeIncidentSupadartModel copyWith({
    Object? id = _unset,
    Object? crimeId = _unset,
    Object? crimeCategoryId = _unset,
    Object? locationId = _unset,
    Object? description = _unset,
    Object? victimCount = _unset,
    Object? status = _unset,
    Object? createdAt = _unset,
    Object? updatedAt = _unset,
    Object? timestamp = _unset,
    Object? crimeCategory = _unset,
    Object? crime = _unset,
    Object? location = _unset,
  }) {
    return CrimeIncidentSupadartModel(
      id: id == _unset ? this.id : id as String,
      crimeId: crimeId == _unset ? this.crimeId : crimeId as String,
      crimeCategoryId:
          crimeCategoryId == _unset
              ? this.crimeCategoryId
              : crimeCategoryId as String,
      locationId: locationId == _unset ? this.locationId : locationId as String,
      description:
          description == _unset ? this.description : description as String,
      victimCount:
          victimCount == _unset ? this.victimCount : victimCount as int,
      status: status == _unset ? this.status : status as CRIME_STATUS?,
      createdAt: createdAt == _unset ? this.createdAt : createdAt as DateTime?,
      updatedAt: updatedAt == _unset ? this.updatedAt : updatedAt as DateTime?,
      timestamp: timestamp == _unset ? this.timestamp : timestamp as DateTime,
      crimeCategory:
          crimeCategory == _unset
              ? this.crimeCategory
              : crimeCategory as CrimeCategorySupadartModel?,
      crime: crime == _unset ? this.crime : crime as CrimeSupadartModel?,
      location:
          location == _unset
              ? this.location
              : location as LocationSupadartModel?,
    );
  }
}
