import 'package:json_annotation/json_annotation.dart';
import 'package:krow/core/data/models/event/business_model.dart';
import 'package:krow/core/data/models/event/event_model.dart';
import 'package:krow/features/invoice/data/models/invoice_decline_model.dart';
import 'package:krow/features/invoice/data/models/invoice_item_model.dart';

part 'invoice_model.g.dart';

enum InvoiceStatus { open, disputed, resolved, paid, overdue, verified }

@JsonSerializable(fieldRename: FieldRename.snake)
class InvoiceModel {
  final String id;
  final InvoiceStatus status;
  final BusinessModel? business;
  final EventModel? event;
  final String? contractType;
  final String? contractValue;
  final String? dueAt;
  final double? total;
  final double? addonsAmount;
  final double? workAmount;
  final List<InvoiceItemModel>? items;
  final InvoiceDeclineModel? dispute;

  factory InvoiceModel.fromJson(Map<String, dynamic> json) {
    return _$InvoiceModelFromJson(json);
  }

  InvoiceModel(
      {required this.id,
      required this.status,
      required this.business,
      required this.event,
      required this.contractType,
      required this.contractValue,
      required this.total,
      required this.addonsAmount,
      required this.dueAt,
      required this.workAmount,
      required this.items,
      required this.dispute});

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

  copyWith({
    String? id,
    InvoiceStatus? status,
    BusinessModel? business,
    EventModel? event,
    String? contractType,
    String? contractValue,
    String? dueAt,
    double? total,
    double? addonsAmount,
    double? workAmount,
    List<InvoiceItemModel>? items,
    InvoiceDeclineModel? dispute,
  }) {
    return InvoiceModel(
      id: id ?? this.id,
      status: status ?? this.status,
      business: business ?? this.business,
      event: event ?? this.event,
      contractType: contractType ?? this.contractType,
      contractValue: contractValue ?? this.contractValue,
      total: total ?? this.total,
      addonsAmount: addonsAmount ?? this.addonsAmount,
      workAmount: workAmount ?? this.workAmount,
      items: items ?? this.items,
      dueAt: dueAt ?? this.dueAt,
      dispute: dispute ?? this.dispute,
    );
  }
}
