// 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 EventSupadartModel implements SupadartClass<EventSupadartModel> {
  final String id;
  final String name;
  final String? description;
  final String code;
  final DateTime createdAt;
  final String userId;
  final UserSupadartModel? user;

  const EventSupadartModel({
    required this.id,
    required this.name,
    this.description,
    required this.code,
    required this.createdAt,
    required this.userId,
    this.user,
  });

  static String get table_name => 'eventSupadartModel';
  static String get c_id => 'id';
  static String get c_name => 'name';
  static String get c_description => 'description';
  static String get c_code => 'code';
  static String get c_createdAt => 'created_at';
  static String get c_userId => 'user_id';

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

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

  static Map<String, dynamic> _generateMap({
    String? id,
    String? name,
    String? description,
    String? code,
    DateTime? createdAt,
    String? userId,
  }) {
    return {
      if (id != null) 'id': id,
      if (name != null) 'name': name,
      if (description != null) 'description': description,
      if (code != null) 'code': code,
      if (createdAt != null) 'created_at': createdAt.toUtc().toIso8601String(),
      if (userId != null) 'user_id': userId,
    };
  }

  static Map<String, dynamic> insert({
    String? id,
    required String name,
    String? description,
    required String code,
    DateTime? createdAt,
    required String userId,
  }) {
    return _generateMap(
      id: id,
      name: name,
      description: description,
      code: code,
      createdAt: createdAt,
      userId: userId,
    );
  }

  static Map<String, dynamic> update({
    String? id,
    String? name,
    String? description,
    String? code,
    DateTime? createdAt,
    String? userId,
  }) {
    return _generateMap(
      id: id,
      name: name,
      description: description,
      code: code,
      createdAt: createdAt,
      userId: userId,
    );
  }

  factory EventSupadartModel.fromJson(Map<String, dynamic> jsonn) {
    return EventSupadartModel(
      id: jsonn['id'] != null ? jsonn['id'].toString() : '',
      name: jsonn['name'] != null ? jsonn['name'].toString() : '',
      description:
          jsonn['description'] != null ? jsonn['description'].toString() : null,
      code: jsonn['code'] != null ? jsonn['code'].toString() : '',
      createdAt:
          jsonn['created_at'] != null
              ? DateTime.parse(jsonn['created_at'].toString())
              : DateTime.fromMillisecondsSinceEpoch(0),
      userId: jsonn['user_id'] != null ? jsonn['user_id'].toString() : '',
      user:
          jsonn['users'] != null
              ? UserSupadartModel.fromJson(
                jsonn['users'] as Map<String, dynamic>,
              )
              : null,
    );
  }

  Map<String, dynamic> toJson() {
    return _generateMap(
      id: id,
      name: name,
      description: description,
      code: code,
      createdAt: createdAt,
      userId: userId,
      // 'users': user?.toJson(),
    );
  }

  static const _unset = Object();
  EventSupadartModel copyWith({
    Object? id = _unset,
    Object? name = _unset,
    Object? description = _unset,
    Object? code = _unset,
    Object? createdAt = _unset,
    Object? userId = _unset,
    Object? user = _unset,
  }) {
    return EventSupadartModel(
      id: id == _unset ? this.id : id as String,
      name: name == _unset ? this.name : name as String,
      description:
          description == _unset ? this.description : description as String?,
      code: code == _unset ? this.code : code as String,
      createdAt: createdAt == _unset ? this.createdAt : createdAt as DateTime,
      userId: userId == _unset ? this.userId : userId as String,
      user: user == _unset ? this.user : user as UserSupadartModel?,
    );
  }
}
