import 'package:json_annotation/json_annotation.dart';


enum LedgerAccountTypeDTO {
  @JsonValue('unspecified')
  unspecified,

  @JsonValue('asset')
  asset,

  @JsonValue('liability')
  liability,

  @JsonValue('revenue')
  revenue,

  @JsonValue('expense')
  expense,
}

LedgerAccountTypeDTO ledgerAccountTypeFromJson(Object? value) {
  final raw = value?.toString() ?? '';
  var normalized = raw.trim().toLowerCase();
  const prefix = 'account_type_';
  if (normalized.startsWith(prefix)) {
    normalized = normalized.substring(prefix.length);
  }
  switch (normalized) {
    case 'asset':
      return LedgerAccountTypeDTO.asset;
    case 'liability':
      return LedgerAccountTypeDTO.liability;
    case 'revenue':
      return LedgerAccountTypeDTO.revenue;
    case 'expense':
      return LedgerAccountTypeDTO.expense;
    case 'unspecified':
    case '':
      return LedgerAccountTypeDTO.unspecified;
    default:
      return LedgerAccountTypeDTO.unspecified;
  }
}

String ledgerAccountTypeToJson(LedgerAccountTypeDTO value) {
  switch (value) {
    case LedgerAccountTypeDTO.asset:
      return 'asset';
    case LedgerAccountTypeDTO.liability:
      return 'liability';
    case LedgerAccountTypeDTO.revenue:
      return 'revenue';
    case LedgerAccountTypeDTO.expense:
      return 'expense';
    case LedgerAccountTypeDTO.unspecified:
      return 'unspecified';
  }
}
