import 'dart:ui';

import 'package:json_annotation/json_annotation.dart';

import '../global/utils.dart';

part 'budget_category_model.g.dart';

@JsonSerializable()
class BudgetCategory {
  const BudgetCategory({
    this.id,
    required this.budgetId,
    required this.name,
    required this.color,
    this.createdAt,
    this.updatedAt,
    required this.amount,
    this.hide = false,
  });

  final int budgetId;
  final int? id;
  final String name;
  final double amount;

  @JsonKey(fromJson: boolFromJson, toJson: boolToJson)
  final bool hide;

  @JsonKey(fromJson: colorFromJson, toJson: colorToJson)
  final Color color;

  @JsonKey(fromJson: dateFromJson, toJson: dateToJson)
  final DateTime? createdAt;

  @JsonKey(fromJson: dateFromJson, toJson: dateToJson)
  final DateTime? updatedAt;

  factory BudgetCategory.fromJson(Map<String, dynamic> json) =>
      _$BudgetCategoryFromJson(json);

  Map<String, dynamic> toJson() => _$BudgetCategoryToJson(this);

  factory BudgetCategory.copyWith(
          {required BudgetCategory category,
          required Map<String, dynamic> data}) =>
      BudgetCategory(
        id: data['id'] ?? category.id,
        budgetId: data['budget_id'] ?? category.budgetId,
        name: data['name'] ?? category.name,
        color: data['color'] ?? category.color,
        createdAt: data['created_at'] ?? category.createdAt,
        updatedAt: data['updated_at'] ?? category.updatedAt,
        amount: data['amount'] ?? category.amount,
        hide: data['hide'] ?? category.hide,
      );
}
