// 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 PermissionSupadartModel
    implements SupadartClass<PermissionSupadartModel> {
  final String id;
  final String action;
  final String resourceId;
  final String roleId;
  final DateTime createdAt;
  final DateTime updatedAt;
  final ResourceSupadartModel? resource;
  final RoleSupadartModel? role;

  const PermissionSupadartModel({
    required this.id,
    required this.action,
    required this.resourceId,
    required this.roleId,
    required this.createdAt,
    required this.updatedAt,
    this.resource,
    this.role,
  });

  static String get table_name => 'permissionSupadartModel';
  static String get c_id => 'id';
  static String get c_action => 'action';
  static String get c_resourceId => 'resource_id';
  static String get c_roleId => 'role_id';
  static String get c_createdAt => 'created_at';
  static String get c_updatedAt => 'updated_at';

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

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

  static Map<String, dynamic> _generateMap({
    String? id,
    String? action,
    String? resourceId,
    String? roleId,
    DateTime? createdAt,
    DateTime? updatedAt,
  }) {
    return {
      if (id != null) 'id': id,
      if (action != null) 'action': action,
      if (resourceId != null) 'resource_id': resourceId,
      if (roleId != null) 'role_id': roleId,
      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 action,
    required String resourceId,
    required String roleId,
    DateTime? createdAt,
    required DateTime updatedAt,
  }) {
    return _generateMap(
      id: id,
      action: action,
      resourceId: resourceId,
      roleId: roleId,
      createdAt: createdAt,
      updatedAt: updatedAt,
    );
  }

  static Map<String, dynamic> update({
    String? id,
    String? action,
    String? resourceId,
    String? roleId,
    DateTime? createdAt,
    DateTime? updatedAt,
  }) {
    return _generateMap(
      id: id,
      action: action,
      resourceId: resourceId,
      roleId: roleId,
      createdAt: createdAt,
      updatedAt: updatedAt,
    );
  }

  factory PermissionSupadartModel.fromJson(Map<String, dynamic> jsonn) {
    return PermissionSupadartModel(
      id: jsonn['id'] != null ? jsonn['id'].toString() : '',
      action: jsonn['action'] != null ? jsonn['action'].toString() : '',
      resourceId:
          jsonn['resource_id'] != null ? jsonn['resource_id'].toString() : '',
      roleId: jsonn['role_id'] != null ? jsonn['role_id'].toString() : '',
      createdAt:
          jsonn['created_at'] != null
              ? DateTime.parse(jsonn['created_at'].toString())
              : DateTime.fromMillisecondsSinceEpoch(0),
      updatedAt:
          jsonn['updated_at'] != null
              ? DateTime.parse(jsonn['updated_at'].toString())
              : DateTime.fromMillisecondsSinceEpoch(0),
      resource:
          jsonn['resources'] != null
              ? ResourceSupadartModel.fromJson(
                jsonn['resources'] as Map<String, dynamic>,
              )
              : null,
      role:
          jsonn['roles'] != null
              ? RoleSupadartModel.fromJson(
                jsonn['roles'] as Map<String, dynamic>,
              )
              : null,
    );
  }

  Map<String, dynamic> toJson() {
    return _generateMap(
      id: id,
      action: action,
      resourceId: resourceId,
      roleId: roleId,
      createdAt: createdAt,
      updatedAt: updatedAt,
      // 'resources': resource?.toJson(),
      // 'roles': role?.toJson(),
    );
  }

  static const _unset = Object();
  PermissionSupadartModel copyWith({
    Object? id = _unset,
    Object? action = _unset,
    Object? resourceId = _unset,
    Object? roleId = _unset,
    Object? createdAt = _unset,
    Object? updatedAt = _unset,
    Object? resource = _unset,
    Object? role = _unset,
  }) {
    return PermissionSupadartModel(
      id: id == _unset ? this.id : id as String,
      action: action == _unset ? this.action : action as String,
      resourceId: resourceId == _unset ? this.resourceId : resourceId as String,
      roleId: roleId == _unset ? this.roleId : roleId as String,
      createdAt: createdAt == _unset ? this.createdAt : createdAt as DateTime,
      updatedAt: updatedAt == _unset ? this.updatedAt : updatedAt as DateTime,
      resource:
          resource == _unset
              ? this.resource
              : resource as ResourceSupadartModel?,
      role: role == _unset ? this.role : role as RoleSupadartModel?,
    );
  }
}
