import 'package:json_annotation/json_annotation.dart';
import 'package:krow/core/data/models/event/addon_model.dart';
import 'package:krow/core/data/models/event/business_model.dart';
import 'package:krow/core/data/models/event/hub_model.dart';
import 'package:krow/core/data/models/event/tag_model.dart';
import 'package:krow/core/data/models/shift/shift_model.dart';
import 'package:krow/core/entity/event_entity.dart';

part 'event_model.g.dart';

@JsonSerializable(fieldRename: FieldRename.snake)
class EventModel {
  final String id;
  final BusinessModel? business;
  final HubModel? hub;
  final String name;
  @JsonKey(unknownEnumValue: EventStatus.draft)
  final EventStatus status;
  final String date;
  final String startTime;
  final String endTime;
  final String? purchaseOrder;
  // @JsonKey(unknownEnumValue: EventContractType.direct)
  // final EventContractType contractType;
  @JsonKey(unknownEnumValue: EventScheduleType.oneTime)
  final EventScheduleType? scheduleType;
  final String? additionalInfo;
  @JsonKey(defaultValue: [])
  final List<AddonModel> addons;
  @JsonKey(defaultValue: [])
  final List<TagModel> tags;
  @JsonKey(defaultValue: [])
  final List<ShiftModel> shifts;

  EventModel(
      {required this.id,
      required this.business,
      required this.hub,
      required this.name,
      required this.status,
      required this.date,
      required this.startTime,
      required this.endTime,
      required this.purchaseOrder,
      // required this.contractType,
      required this.scheduleType,
      required this.additionalInfo,
      required this.addons,
      required this.tags,
      required this.shifts});

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

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

@JsonEnum(fieldRename: FieldRename.snake)
enum EventContractType {
  direct,
  contract,
  purchaseOrder,
}

@JsonEnum(fieldRename: FieldRename.snake)
enum EventScheduleType {
  oneTime,
  recurring,
}

extension on EventScheduleType {
  String get formattedName {
    return switch (this) {
      EventScheduleType.oneTime => 'One Time',
      EventScheduleType.recurring => 'Recurring'
    };
  }
}
