// 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 SESSION_STATUS { active, completed }

class SessionSupadartModel implements SupadartClass<SessionSupadartModel> {
  final String id;
  final String userId;
  final String eventId;
  final SESSION_STATUS status;
  final DateTime createdAt;
  final EventSupadartModel? event;
  final UserSupadartModel? user;

  const SessionSupadartModel({
    required this.id,
    required this.userId,
    required this.eventId,
    required this.status,
    required this.createdAt,
    this.event,
    this.user,
  });

  static String get table_name => 'sessionSupadartModel';
  static String get c_id => 'id';
  static String get c_userId => 'user_id';
  static String get c_eventId => 'event_id';
  static String get c_status => 'status';
  static String get c_createdAt => 'created_at';

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

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

  static Map<String, dynamic> _generateMap({
    String? id,
    String? userId,
    String? eventId,
    SESSION_STATUS? status,
    DateTime? createdAt,
  }) {
    return {
      if (id != null) 'id': id,
      if (userId != null) 'user_id': userId,
      if (eventId != null) 'event_id': eventId,
      if (status != null) 'status': status.toString().split('.').last,
      if (createdAt != null) 'created_at': createdAt.toUtc().toIso8601String(),
    };
  }

  static Map<String, dynamic> insert({
    String? id,
    required String userId,
    required String eventId,
    SESSION_STATUS? status,
    DateTime? createdAt,
  }) {
    return _generateMap(
      id: id,
      userId: userId,
      eventId: eventId,
      status: status,
      createdAt: createdAt,
    );
  }

  static Map<String, dynamic> update({
    String? id,
    String? userId,
    String? eventId,
    SESSION_STATUS? status,
    DateTime? createdAt,
  }) {
    return _generateMap(
      id: id,
      userId: userId,
      eventId: eventId,
      status: status,
      createdAt: createdAt,
    );
  }

  factory SessionSupadartModel.fromJson(Map<String, dynamic> jsonn) {
    return SessionSupadartModel(
      id: jsonn['id'] != null ? jsonn['id'].toString() : '',
      userId: jsonn['user_id'] != null ? jsonn['user_id'].toString() : '',
      eventId: jsonn['event_id'] != null ? jsonn['event_id'].toString() : '',
      status:
          jsonn['status'] != null
              ? SESSION_STATUS.values.byName(jsonn['status'].toString())
              : SESSION_STATUS.values.first,
      createdAt:
          jsonn['created_at'] != null
              ? DateTime.parse(jsonn['created_at'].toString())
              : DateTime.fromMillisecondsSinceEpoch(0),
      event:
          jsonn['events'] != null
              ? EventSupadartModel.fromJson(
                jsonn['events'] 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,
      eventId: eventId,
      status: status,
      createdAt: createdAt,
      // 'events': event?.toJson(),
      // 'users': user?.toJson(),
    );
  }

  static const _unset = Object();
  SessionSupadartModel copyWith({
    Object? id = _unset,
    Object? userId = _unset,
    Object? eventId = _unset,
    Object? status = _unset,
    Object? createdAt = _unset,
    Object? event = _unset,
    Object? user = _unset,
  }) {
    return SessionSupadartModel(
      id: id == _unset ? this.id : id as String,
      userId: userId == _unset ? this.userId : userId as String,
      eventId: eventId == _unset ? this.eventId : eventId as String,
      status: status == _unset ? this.status : status as SESSION_STATUS,
      createdAt: createdAt == _unset ? this.createdAt : createdAt as DateTime,
      event: event == _unset ? this.event : event as EventSupadartModel?,
      user: user == _unset ? this.user : user as UserSupadartModel?,
    );
  }
}
