export class HealthKitIdentifier {
  private constructor(private readonly value: string) {
    this.validate();
  }

  static create(identifier: string): HealthKitIdentifier {
    return new HealthKitIdentifier(identifier);
  }

  private validate(): void {
    if (!this.value || this.value.trim().length === 0) {
      throw new Error('HealthKit identifier cannot be empty');
    }
    
    if (!this.value.startsWith('HK')) {
      throw new Error('HealthKit identifier must start with "HK"');
    }
  }

  toString(): string {
    return this.value;
  }

  equals(other: HealthKitIdentifier): boolean {
    return this.value === other.value;
  }
}

export class HealthKitUnit {
  private constructor(private readonly value: string) {
    this.validate();
  }

  static create(unit: string): HealthKitUnit {
    return new HealthKitUnit(unit);
  }

  private validate(): void {
    if (!this.value || this.value.trim().length === 0) {
      throw new Error('HealthKit unit cannot be empty');
    }
  }

  toString(): string {
    return this.value;
  }

  equals(other: HealthKitUnit): boolean {
    return this.value === other.value;
  }
}

export class DateRange {
  constructor(
    public readonly startDate: Date,
    public readonly endDate: Date
  ) {
    this.validate();
  }

  private validate(): void {
    if (this.startDate >= this.endDate) {
      throw new Error('Start date must be before end date');
    }
  }

  getDurationInDays(): number {
    const diffTime = Math.abs(this.endDate.getTime() - this.startDate.getTime());
    return Math.ceil(diffTime / (1000 * 60 * 60 * 24));
  }
} 