// 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 UnitStatisticSupadartModel
    implements SupadartClass<UnitStatisticSupadartModel> {
  final String id;
  final int crimeTotal;
  final int crimeCleared;
  final double? percentage;
  final int? pending;
  final int month;
  final int year;
  final DateTime? createdAt;
  final DateTime? updatedAt;
  final String codeUnit;
  final UnitSupadartModel? unit;

  const UnitStatisticSupadartModel({
    required this.id,
    required this.crimeTotal,
    required this.crimeCleared,
    this.percentage,
    this.pending,
    required this.month,
    required this.year,
    this.createdAt,
    this.updatedAt,
    required this.codeUnit,
    this.unit,
  });

  static String get table_name => 'unit_statistics';
  static String get c_id => 'id';
  static String get c_crimeTotal => 'crime_total';
  static String get c_crimeCleared => 'crime_cleared';
  static String get c_percentage => 'percentage';
  static String get c_pending => 'pending';
  static String get c_month => 'month';
  static String get c_year => 'year';
  static String get c_createdAt => 'created_at';
  static String get c_updatedAt => 'updated_at';
  static String get c_codeUnit => 'code_unit';

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

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

  static Map<String, dynamic> _generateMap({
    String? id,
    int? crimeTotal,
    int? crimeCleared,
    double? percentage,
    int? pending,
    int? month,
    int? year,
    DateTime? createdAt,
    DateTime? updatedAt,
    String? codeUnit,
  }) {
    return {
      if (id != null) 'id': id,
      if (crimeTotal != null) 'crime_total': crimeTotal,
      if (crimeCleared != null) 'crime_cleared': crimeCleared,
      if (percentage != null) 'percentage': percentage.toString(),
      if (pending != null) 'pending': pending,
      if (month != null) 'month': month,
      if (year != null) 'year': year,
      if (createdAt != null) 'created_at': createdAt.toUtc().toIso8601String(),
      if (updatedAt != null) 'updated_at': updatedAt.toUtc().toIso8601String(),
      if (codeUnit != null) 'code_unit': codeUnit,
    };
  }

  static Map<String, dynamic> insert({
    String? id,
    required int crimeTotal,
    required int crimeCleared,
    double? percentage,
    int? pending,
    required int month,
    required int year,
    DateTime? createdAt,
    DateTime? updatedAt,
    required String codeUnit,
  }) {
    return _generateMap(
      id: id,
      crimeTotal: crimeTotal,
      crimeCleared: crimeCleared,
      percentage: percentage,
      pending: pending,
      month: month,
      year: year,
      createdAt: createdAt,
      updatedAt: updatedAt,
      codeUnit: codeUnit,
    );
  }

  static Map<String, dynamic> update({
    String? id,
    int? crimeTotal,
    int? crimeCleared,
    double? percentage,
    int? pending,
    int? month,
    int? year,
    DateTime? createdAt,
    DateTime? updatedAt,
    String? codeUnit,
  }) {
    return _generateMap(
      id: id,
      crimeTotal: crimeTotal,
      crimeCleared: crimeCleared,
      percentage: percentage,
      pending: pending,
      month: month,
      year: year,
      createdAt: createdAt,
      updatedAt: updatedAt,
      codeUnit: codeUnit,
    );
  }

  factory UnitStatisticSupadartModel.fromJson(Map<String, dynamic> jsonn) {
    return UnitStatisticSupadartModel(
      id: jsonn['id'] != null ? jsonn['id'].toString() : '',
      crimeTotal:
          jsonn['crime_total'] != null
              ? int.parse(jsonn['crime_total'].toString())
              : 0,
      crimeCleared:
          jsonn['crime_cleared'] != null
              ? int.parse(jsonn['crime_cleared'].toString())
              : 0,
      percentage:
          jsonn['percentage'] != null
              ? double.parse(jsonn['percentage'].toString())
              : null,
      pending:
          jsonn['pending'] != null
              ? int.parse(jsonn['pending'].toString())
              : null,
      month: jsonn['month'] != null ? int.parse(jsonn['month'].toString()) : 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,
      codeUnit: jsonn['code_unit'] != null ? jsonn['code_unit'].toString() : '',
      unit:
          jsonn['unitUnitSupadartModel'] != null
              ? UnitSupadartModel.fromJson(
                jsonn['unitUnitSupadartModel'] as Map<String, dynamic>,
              )
              : null,
    );
  }

  Map<String, dynamic> toJson() {
    return _generateMap(
      id: id,
      crimeTotal: crimeTotal,
      crimeCleared: crimeCleared,
      percentage: percentage,
      pending: pending,
      month: month,
      year: year,
      createdAt: createdAt,
      updatedAt: updatedAt,
      codeUnit: codeUnit,
      // 'unitUnitSupadartModel': unit?.toJson(),
    );
  }

  static const _unset = Object();
  UnitStatisticSupadartModel copyWith({
    Object? id = _unset,
    Object? crimeTotal = _unset,
    Object? crimeCleared = _unset,
    Object? percentage = _unset,
    Object? pending = _unset,
    Object? month = _unset,
    Object? year = _unset,
    Object? createdAt = _unset,
    Object? updatedAt = _unset,
    Object? codeUnit = _unset,
    Object? unit = _unset,
  }) {
    return UnitStatisticSupadartModel(
      id: id == _unset ? this.id : id as String,
      crimeTotal: crimeTotal == _unset ? this.crimeTotal : crimeTotal as int,
      crimeCleared:
          crimeCleared == _unset ? this.crimeCleared : crimeCleared as int,
      percentage:
          percentage == _unset ? this.percentage : percentage as double?,
      pending: pending == _unset ? this.pending : pending as int?,
      month: month == _unset ? this.month : month as int,
      year: year == _unset ? this.year : year as int,
      createdAt: createdAt == _unset ? this.createdAt : createdAt as DateTime?,
      updatedAt: updatedAt == _unset ? this.updatedAt : updatedAt as DateTime?,
      codeUnit: codeUnit == _unset ? this.codeUnit : codeUnit as String,
      unit: unit == _unset ? this.unit : unit as UnitSupadartModel?,
    );
  }
}
