part of 'create_event_bloc.dart';

@immutable
class CreateEventState {
  final bool inLoading;
  final bool success;
  final bool valid;
  final EventEntity entity;
  final EventScheduleType recurringType;
  final List<HubModel> hubs;
  final List<TagModel> tags;
  final List<BusinessMemberModel> contacts;
  final List<ShiftViewModel> shifts;
  final List<AddonModel> addons;
  final List<BusinessSkillModel> skills;
  final List<DepartmentModel> departments;
  final EventValidationState? validationState;

  final bool showEmptyFieldError;

  const CreateEventState(
      {required this.entity,
      this.inLoading = false,
      this.valid = false,
      this.showEmptyFieldError = false,
      this.success = false,
      this.recurringType = EventScheduleType.oneTime,
      this.hubs = const [],
      this.tags = const [],
      this.contacts = const [],
      this.addons = const [],
      this.skills = const [],
      this.shifts = const [],
      this.departments = const [],
      this.validationState});

  CreateEventState copyWith({
    bool? inLoading,
    bool? success,
    bool? valid,
    bool? showEmptyFieldError,
    EventEntity? entity,
    EventScheduleType? recurringType,
    List<HubModel>? hubs,
    List<TagModel>? tags,
    List<BusinessMemberModel>? contacts,
    List<ShiftViewModel>? shifts,
    List<AddonModel>? addons,
    List<BusinessSkillModel>? skills,
    List<DepartmentModel>? departments,
    EventValidationState? validationState,
  }) {
    return CreateEventState(
      success: success ?? this.success,
      valid: valid ?? this.valid,
      inLoading: inLoading ?? this.inLoading,
      showEmptyFieldError: showEmptyFieldError ?? this.showEmptyFieldError,
      entity: entity ?? this.entity,
      recurringType: recurringType ?? this.recurringType,
      hubs: hubs ?? this.hubs,
      tags: tags ?? this.tags,
      contacts: contacts ?? this.contacts,
      shifts: shifts ?? this.shifts,
      addons: addons ?? this.addons,
      skills: skills ?? this.skills,
      departments: departments ?? this.departments,
      validationState: validationState,
    );
  }
}

class ShiftViewModel {
  final String id;
  final CreateShiftDetailsBloc bloc;

  ShiftViewModel({required this.id, required this.bloc});
}

class EventValidationState {
  final String? nameError;
  final String? startDateError;
  final String? endDateError;
  final String? hubError;
  // final String? contractNumberError;
  final String? poNumberError;
  final String? shiftsError;

  bool showed = false;

  bool get hasError =>
      nameError != null ||
      startDateError != null ||
      endDateError != null ||
      hubError != null ||
      // contractNumberError != null ||
      poNumberError != null ||
      shiftsError != null;

  String? get message {
    return nameError ??
        startDateError ??
        endDateError ??
        hubError ??
        // contractNumberError ??
        poNumberError ??
        shiftsError ??
        '';
  }

  EventValidationState(
      {this.nameError,
      this.startDateError,
      this.endDateError,
      this.hubError,
      // this.contractNumberError,
      this.poNumberError,
      this.shiftsError});

  EventValidationState copyWith({
    String? nameError,
    String? startDateError,
    String? endDateError,
    String? hubError,
    // String? contractNumberError,
    String? poNumberError,
    String? shiftsError,
  }) {
    return EventValidationState(
      nameError: nameError ?? this.nameError,
      startDateError: startDateError ?? this.startDateError,
      endDateError: endDateError ?? this.endDateError,
      hubError: hubError ?? this.hubError,
      // contractNumberError: contractNumberError ?? this.contractNumberError,
      poNumberError: poNumberError ?? this.poNumberError,
      shiftsError: shiftsError ?? this.shiftsError,
    );
  }
}
