// 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_header.dart';

class PrismaMigrations implements SupadartClass<PrismaMigrations> {
  final String id;
  final String checksum;
  final DateTime? finishedAt;
  final String migrationName;
  final String? logs;
  final DateTime? rolledBackAt;
  final DateTime startedAt;
  final int appliedStepsCount;

  const PrismaMigrations({
    required this.id,
    required this.checksum,
    this.finishedAt,
    required this.migrationName,
    this.logs,
    this.rolledBackAt,
    required this.startedAt,
    required this.appliedStepsCount,
  });

  static String get table_name => '_prisma_migrations';
  static String get c_id => 'id';
  static String get c_checksum => 'checksum';
  static String get c_finishedAt => 'finished_at';
  static String get c_migrationName => 'migration_name';
  static String get c_logs => 'logs';
  static String get c_rolledBackAt => 'rolled_back_at';
  static String get c_startedAt => 'started_at';
  static String get c_appliedStepsCount => 'applied_steps_count';

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

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

  static Map<String, dynamic> _generateMap({
    String? id,
    String? checksum,
    DateTime? finishedAt,
    String? migrationName,
    String? logs,
    DateTime? rolledBackAt,
    DateTime? startedAt,
    int? appliedStepsCount,
  }) {
    return {
      if (id != null) 'id': id,
      if (checksum != null) 'checksum': checksum,
      if (finishedAt != null)
        'finished_at': finishedAt.toUtc().toIso8601String(),
      if (migrationName != null) 'migration_name': migrationName,
      if (logs != null) 'logs': logs,
      if (rolledBackAt != null)
        'rolled_back_at': rolledBackAt.toUtc().toIso8601String(),
      if (startedAt != null) 'started_at': startedAt.toUtc().toIso8601String(),
      if (appliedStepsCount != null) 'applied_steps_count': appliedStepsCount,
    };
  }

  static Map<String, dynamic> insert({
    String? id,
    required String checksum,
    DateTime? finishedAt,
    required String migrationName,
    String? logs,
    DateTime? rolledBackAt,
    DateTime? startedAt,
    int? appliedStepsCount,
  }) {
    return _generateMap(
      id: id,
      checksum: checksum,
      finishedAt: finishedAt,
      migrationName: migrationName,
      logs: logs,
      rolledBackAt: rolledBackAt,
      startedAt: startedAt,
      appliedStepsCount: appliedStepsCount,
    );
  }

  static Map<String, dynamic> update({
    String? id,
    String? checksum,
    DateTime? finishedAt,
    String? migrationName,
    String? logs,
    DateTime? rolledBackAt,
    DateTime? startedAt,
    int? appliedStepsCount,
  }) {
    return _generateMap(
      id: id,
      checksum: checksum,
      finishedAt: finishedAt,
      migrationName: migrationName,
      logs: logs,
      rolledBackAt: rolledBackAt,
      startedAt: startedAt,
      appliedStepsCount: appliedStepsCount,
    );
  }

  factory PrismaMigrations.fromJson(Map<String, dynamic> jsonn) {
    return PrismaMigrations(
      id: jsonn['id'] != null ? jsonn['id'].toString() : '',
      checksum: jsonn['checksum'] != null ? jsonn['checksum'].toString() : '',
      finishedAt:
          jsonn['finished_at'] != null
              ? DateTime.parse(jsonn['finished_at'].toString())
              : null,
      migrationName:
          jsonn['migration_name'] != null
              ? jsonn['migration_name'].toString()
              : '',
      logs: jsonn['logs'] != null ? jsonn['logs'].toString() : null,
      rolledBackAt:
          jsonn['rolled_back_at'] != null
              ? DateTime.parse(jsonn['rolled_back_at'].toString())
              : null,
      startedAt:
          jsonn['started_at'] != null
              ? DateTime.parse(jsonn['started_at'].toString())
              : DateTime.fromMillisecondsSinceEpoch(0),
      appliedStepsCount:
          jsonn['applied_steps_count'] != null
              ? int.parse(jsonn['applied_steps_count'].toString())
              : 0,
    );
  }

  Map<String, dynamic> toJson() {
    return _generateMap(
      id: id,
      checksum: checksum,
      finishedAt: finishedAt,
      migrationName: migrationName,
      logs: logs,
      rolledBackAt: rolledBackAt,
      startedAt: startedAt,
      appliedStepsCount: appliedStepsCount,
    );
  }

  static const _unset = Object();
  PrismaMigrations copyWith({
    Object? id = _unset,
    Object? checksum = _unset,
    Object? finishedAt = _unset,
    Object? migrationName = _unset,
    Object? logs = _unset,
    Object? rolledBackAt = _unset,
    Object? startedAt = _unset,
    Object? appliedStepsCount = _unset,
  }) {
    return PrismaMigrations(
      id: id == _unset ? this.id : id as String,
      checksum: checksum == _unset ? this.checksum : checksum as String,
      finishedAt:
          finishedAt == _unset ? this.finishedAt : finishedAt as DateTime?,
      migrationName:
          migrationName == _unset
              ? this.migrationName
              : migrationName as String,
      logs: logs == _unset ? this.logs : logs as String?,
      rolledBackAt:
          rolledBackAt == _unset
              ? this.rolledBackAt
              : rolledBackAt as DateTime?,
      startedAt: startedAt == _unset ? this.startedAt : startedAt as DateTime,
      appliedStepsCount:
          appliedStepsCount == _unset
              ? this.appliedStepsCount
              : appliedStepsCount as int,
    );
  }
}
