import 'package:json_annotation/json_annotation.dart';
import 'package:krow/core/data/models/shift/event_shift_position_model.dart';
import 'package:krow/core/data/models/staff/staff_cancel_reason.dart';

part 'pivot.g.dart';

@JsonEnum(fieldRename: FieldRename.snake)
enum PivotStatus {
  assigned,
  confirmed,
  ongoing,
  completed,
  declineByStaff,
  canceledByStaff,
  canceledByBusiness,
  canceledByAdmin,
  requestedReplace,
  noShowed,

}

extension PivotStatusToString on PivotStatus {
  String get formattedName {
    switch (this) {
      case PivotStatus.assigned:
        return 'Assigned';
      case PivotStatus.confirmed:
        return 'Confirmed';
      case PivotStatus.ongoing:
        return 'Ongoing';
      case PivotStatus.completed:
        return 'Completed';
      case PivotStatus.declineByStaff:
        return 'Declined by Staff';
        case PivotStatus.canceledByStaff:
        return 'Canceled by Staff';
      case PivotStatus.canceledByBusiness:
        return 'Canceled by Business';
      case PivotStatus.canceledByAdmin:
        return 'Canceled by Admin';
      case PivotStatus.requestedReplace:
        return 'Requested Replace';
      case PivotStatus.noShowed:
        return 'No Showed';
    }
  }
}


@JsonSerializable(fieldRename: FieldRename.snake)
class Pivot {
  String id;
  @JsonKey(unknownEnumValue: PivotStatus.assigned)
  PivotStatus status;
  String? statusUpdatedAt;
  String startAt;
  String endAt;
  String? clockIn;
  String? clockOut;
  String? breakIn;
  String? breakOut;
  EventShiftPositionModel? position;
  List<StaffCancelReason>? cancelReason;
  Rating? rating;

  Pivot({
    required this.id,
    required this.status,
    this.statusUpdatedAt,
    required this.startAt,
    required this.endAt,
    this.clockIn,
    this.clockOut,
    this.breakIn,
    this.breakOut,
    this.position,
    this.cancelReason,
  });

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

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

@JsonSerializable(fieldRename: FieldRename.snake)
class Rating {
  final String id;
  final double rating;

  Rating({required this.id, required this.rating});

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

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