// 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 PanicButtonLogSupadartModel
    implements SupadartClass<PanicButtonLogSupadartModel> {
  final String id;
  final String userId;
  final String? officerId;
  final String incidentId;
  final DateTime timestamp;
  final IncidentLogSupadartModel? incident;
  final OfficerSupadartModel? officer;
  final UserSupadartModel? user;

  const PanicButtonLogSupadartModel({
    required this.id,
    required this.userId,
    this.officerId,
    required this.incidentId,
    required this.timestamp,
    this.incident,
    this.officer,
    this.user,
  });

  static String get table_name => 'panic_button_logs';
  static String get c_id => 'id';
  static String get c_userId => 'user_id';
  static String get c_officerId => 'officer_id';
  static String get c_incidentId => 'incident_id';
  static String get c_timestamp => 'timestamp';

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

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

  static Map<String, dynamic> _generateMap({
    String? id,
    String? userId,
    String? officerId,
    String? incidentId,
    DateTime? timestamp,
  }) {
    return {
      if (id != null) 'id': id,
      if (userId != null) 'user_id': userId,
      if (officerId != null) 'officer_id': officerId,
      if (incidentId != null) 'incident_id': incidentId,
      if (timestamp != null) 'timestamp': timestamp.toUtc().toIso8601String(),
    };
  }

  static Map<String, dynamic> insert({
    String? id,
    required String userId,
    String? officerId,
    required String incidentId,
    required DateTime timestamp,
  }) {
    return _generateMap(
      id: id,
      userId: userId,
      officerId: officerId,
      incidentId: incidentId,
      timestamp: timestamp,
    );
  }

  static Map<String, dynamic> update({
    String? id,
    String? userId,
    String? officerId,
    String? incidentId,
    DateTime? timestamp,
  }) {
    return _generateMap(
      id: id,
      userId: userId,
      officerId: officerId,
      incidentId: incidentId,
      timestamp: timestamp,
    );
  }

  factory PanicButtonLogSupadartModel.fromJson(Map<String, dynamic> jsonn) {
    return PanicButtonLogSupadartModel(
      id: jsonn['id'] != null ? jsonn['id'].toString() : '',
      userId: jsonn['user_id'] != null ? jsonn['user_id'].toString() : '',
      officerId:
          jsonn['officer_id'] != null ? jsonn['officer_id'].toString() : null,
      incidentId:
          jsonn['incident_id'] != null ? jsonn['incident_id'].toString() : '',
      timestamp:
          jsonn['timestamp'] != null
              ? DateTime.parse(jsonn['timestamp'].toString())
              : DateTime.fromMillisecondsSinceEpoch(0),
      incident:
          jsonn['incident_logs'] != null
              ? IncidentLogSupadartModel.fromJson(
                jsonn['incident_logs'] as Map<String, dynamic>,
              )
              : null,
      officer:
          jsonn['officers'] != null
              ? OfficerSupadartModel.fromJson(
                jsonn['officers'] 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,
      officerId: officerId,
      incidentId: incidentId,
      timestamp: timestamp,
      // 'incident_logs': incident?.toJson(),
      // 'officers': officer?.toJson(),
      // 'users': user?.toJson(),
    );
  }

  static const _unset = Object();
  PanicButtonLogSupadartModel copyWith({
    Object? id = _unset,
    Object? userId = _unset,
    Object? officerId = _unset,
    Object? incidentId = _unset,
    Object? timestamp = _unset,
    Object? incident = _unset,
    Object? officer = _unset,
    Object? user = _unset,
  }) {
    return PanicButtonLogSupadartModel(
      id: id == _unset ? this.id : id as String,
      userId: userId == _unset ? this.userId : userId as String,
      officerId: officerId == _unset ? this.officerId : officerId as String?,
      incidentId: incidentId == _unset ? this.incidentId : incidentId as String,
      timestamp: timestamp == _unset ? this.timestamp : timestamp as DateTime,
      incident:
          incident == _unset
              ? this.incident
              : incident as IncidentLogSupadartModel?,
      officer:
          officer == _unset ? this.officer : officer as OfficerSupadartModel?,
      user: user == _unset ? this.user : user as UserSupadartModel?,
    );
  }
}
