import 'package:flutter/material.dart';

class BookableSpaceConfig {
  String configUuid;
  List<String> bookableDays;
  TimeOfDay? bookingStartTime;
  TimeOfDay? bookingEndTime;
  int cost;
  bool availability;
  BookableSpaceConfig({
    required this.configUuid,
    required this.availability,
    required this.bookableDays,
    this.bookingEndTime,
    this.bookingStartTime,
    required this.cost,
  });
  factory BookableSpaceConfig.zero() => BookableSpaceConfig(
        configUuid: '',
        bookableDays: [],
        availability: false,
        cost: -1,
      );
  factory BookableSpaceConfig.fromJson(Map<String, dynamic> json) =>
      BookableSpaceConfig(
        configUuid: json['uuid'] as String,
        bookableDays: (json['daysAvailable'] as List).cast<String>(),
        availability: (json['active'] as bool?) ?? false,
        bookingEndTime: parseTimeOfDay(json['startTime'] as String),
        bookingStartTime: parseTimeOfDay(json['endTime'] as String),
        cost: json['points'] as int,
      );

  static TimeOfDay parseTimeOfDay(String timeString) {
    final parts = timeString.split(':');
    final hour = int.parse(parts[0]);
    final minute = int.parse(parts[1]);
    return TimeOfDay(hour: hour, minute: minute);
  }

  bool get isValid =>
      bookableDays.isNotEmpty &&
      cost > 0 &&
      bookingStartTime != null &&
      bookingEndTime != null;
}
