var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);

// src/modules/Resource/index.ts
var Resource_exports = {};
__export(Resource_exports, {
  ResourceListModule: () => ResourceListModule
});
module.exports = __toCommonJS(Resource_exports);
var import_BaseModule = require("../BaseModule");
var import_types = require("./types");
var ResourceListModule = class extends import_BaseModule.BaseModule {
  constructor(name, version) {
    super(name, version);
    this.defaultName = "resourceList";
    this.defaultVersion = "1.0.0";
  }
  async initialize(core, options) {
    this.core = core;
    this.store = options.store;
  }
  async getResources() {
    return this.store.list;
  }
  async selectResource(resourceId) {
    const resource = this.store.list.find((r) => r.id === resourceId);
    if (!resource)
      return;
    this.store.selectedResource = resource;
    await this.core.effects.emit(`${this.name}:onResourceSelect`, resource);
  }
  getSelectedResource() {
    return this.store.selectedResource;
  }
  async checkAvailability(resourceId, start, end) {
    const resource = this.store.list.find((r) => r.id === resourceId);
    if (!resource)
      return false;
    return resource.timeSlots.some(
      (slot) => slot.start.getTime() <= start.getTime() && slot.end.getTime() >= end.getTime() && slot.availableCapacity > 0
    );
  }
  async getAvailableTimeSlots(resourceId) {
    const resource = this.store.list.find((r) => r.id === resourceId);
    if (!resource)
      return [];
    return resource.timeSlots.filter((slot) => slot.availableCapacity > 0);
  }
  getAvailableCapacity(resourceId, timeSlot) {
    const resource = this.store.list.find((r) => r.id === resourceId);
    if (!resource)
      return 0;
    const slot = resource.timeSlots.find(
      (s) => s.start.getTime() === timeSlot.start.getTime() && s.end.getTime() === timeSlot.end.getTime()
    );
    return (slot == null ? void 0 : slot.availableCapacity) || 0;
  }
  async updateResource(resourceId, updates) {
    const index = this.store.list.findIndex((r) => r.id === resourceId);
    if (index === -1)
      return;
    this.store.list[index] = {
      ...this.store.list[index],
      ...updates
    };
    await this.core.effects.emit(
      import_types.ResourceHooks.OnResourceChange,
      this.store.list[index]
    );
  }
};
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  ResourceListModule
});
