// 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 IncidentLogSupadartModel
    implements SupadartClass<IncidentLogSupadartModel> {
  final String id;
  final String userId;
  final String locationId;
  final String categoryId;
  final String? description;
  final String? source;
  final DateTime time;
  final bool? verified;
  final DateTime? createdAt;
  final DateTime? updatedAt;
  final CrimeCategorySupadartModel? category;
  final LocationSupadartModel? location;
  final UserSupadartModel? user;

  const IncidentLogSupadartModel({
    required this.id,
    required this.userId,
    required this.locationId,
    required this.categoryId,
    this.description,
    this.source,
    required this.time,
    this.verified,
    this.createdAt,
    this.updatedAt,
    this.category,
    this.location,
    this.user,
  });

  static String get table_name => 'incident_logs';
  static String get c_id => 'id';
  static String get c_userId => 'user_id';
  static String get c_locationId => 'location_id';
  static String get c_categoryId => 'category_id';
  static String get c_description => 'description';
  static String get c_source => 'source';
  static String get c_time => 'time';
  static String get c_verified => 'verified';
  static String get c_createdAt => 'created_at';
  static String get c_updatedAt => 'updated_at';

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

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

  static Map<String, dynamic> _generateMap({
    String? id,
    String? userId,
    String? locationId,
    String? categoryId,
    String? description,
    String? source,
    DateTime? time,
    bool? verified,
    DateTime? createdAt,
    DateTime? updatedAt,
  }) {
    return {
      if (id != null) 'id': id,
      if (userId != null) 'user_id': userId,
      if (locationId != null) 'location_id': locationId,
      if (categoryId != null) 'category_id': categoryId,
      if (description != null) 'description': description,
      if (source != null) 'source': source,
      if (time != null) 'time': time.toUtc().toIso8601String(),
      if (verified != null) 'verified': verified,
      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 userId,
    required String locationId,
    required String categoryId,
    String? description,
    String? source,
    required DateTime time,
    bool? verified,
    DateTime? createdAt,
    DateTime? updatedAt,
  }) {
    return _generateMap(
      id: id,
      userId: userId,
      locationId: locationId,
      categoryId: categoryId,
      description: description,
      source: source,
      time: time,
      verified: verified,
      createdAt: createdAt,
      updatedAt: updatedAt,
    );
  }

  static Map<String, dynamic> update({
    String? id,
    String? userId,
    String? locationId,
    String? categoryId,
    String? description,
    String? source,
    DateTime? time,
    bool? verified,
    DateTime? createdAt,
    DateTime? updatedAt,
  }) {
    return _generateMap(
      id: id,
      userId: userId,
      locationId: locationId,
      categoryId: categoryId,
      description: description,
      source: source,
      time: time,
      verified: verified,
      createdAt: createdAt,
      updatedAt: updatedAt,
    );
  }

  factory IncidentLogSupadartModel.fromJson(Map<String, dynamic> jsonn) {
    return IncidentLogSupadartModel(
      id: jsonn['id'] != null ? jsonn['id'].toString() : '',
      userId: jsonn['user_id'] != null ? jsonn['user_id'].toString() : '',
      locationId:
          jsonn['location_id'] != null ? jsonn['location_id'].toString() : '',
      categoryId:
          jsonn['category_id'] != null ? jsonn['category_id'].toString() : '',
      description:
          jsonn['description'] != null ? jsonn['description'].toString() : null,
      source: jsonn['source'] != null ? jsonn['source'].toString() : null,
      time:
          jsonn['time'] != null
              ? DateTime.parse(jsonn['time'].toString())
              : DateTime.fromMillisecondsSinceEpoch(0),
      verified: jsonn['verified'] != null ? jsonn['verified'] as bool : 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,
      category:
          jsonn['crime_categories'] != null
              ? CrimeCategorySupadartModel.fromJson(
                jsonn['crime_categories'] as Map<String, dynamic>,
              )
              : null,
      location:
          jsonn['locations'] != null
              ? LocationSupadartModel.fromJson(
                jsonn['locations'] as Map<String, dynamic>,
              )
              : null,
      user:
          jsonn['users'] != null
              ? UserSupadartModel.fromJson(
                jsonn['users'] as Map<String, dynamic>,
              )
              : null,
    );
  }

  Map<String, dynamic> toJson() {
    return _generateMap(
      id: id,
      userId: userId,
      locationId: locationId,
      categoryId: categoryId,
      description: description,
      source: source,
      time: time,
      verified: verified,
      createdAt: createdAt,
      updatedAt: updatedAt,
      // 'crime_categories': category?.toJson(),
      // 'locations': location?.toJson(),
      // 'users': user?.toJson(),
    );
  }

  static const _unset = Object();
  IncidentLogSupadartModel copyWith({
    Object? id = _unset,
    Object? userId = _unset,
    Object? locationId = _unset,
    Object? categoryId = _unset,
    Object? description = _unset,
    Object? source = _unset,
    Object? time = _unset,
    Object? verified = _unset,
    Object? createdAt = _unset,
    Object? updatedAt = _unset,
    Object? category = _unset,
    Object? location = _unset,
    Object? user = _unset,
  }) {
    return IncidentLogSupadartModel(
      id: id == _unset ? this.id : id as String,
      userId: userId == _unset ? this.userId : userId as String,
      locationId: locationId == _unset ? this.locationId : locationId as String,
      categoryId: categoryId == _unset ? this.categoryId : categoryId as String,
      description:
          description == _unset ? this.description : description as String?,
      source: source == _unset ? this.source : source as String?,
      time: time == _unset ? this.time : time as DateTime,
      verified: verified == _unset ? this.verified : verified as bool?,
      createdAt: createdAt == _unset ? this.createdAt : createdAt as DateTime?,
      updatedAt: updatedAt == _unset ? this.updatedAt : updatedAt as DateTime?,
      category:
          category == _unset
              ? this.category
              : category as CrimeCategorySupadartModel?,
      location:
          location == _unset
              ? this.location
              : location as LocationSupadartModel?,
      user: user == _unset ? this.user : user as UserSupadartModel?,
    );
  }
}
