/**
 * Value Object: DownloadUrl
 *
 * Encapsulates a download URL with basic validation.
 * Ensures the URL uses http or https protocol.
 */
export class DownloadUrl {
  private static readonly URL_REGEX =
    /^https?:\/\/[^\s/$.?#].[^\s]*$/i;

  private readonly value: string;

  private constructor(value: string) {
    this.value = value;
  }

  static create(value: string): DownloadUrl {
    if (!value || !DownloadUrl.URL_REGEX.test(value)) {
      throw new Error(
        `Invalid download URL: "${value}". Must be a valid HTTP or HTTPS URL.`,
      );
    }
    return new DownloadUrl(value);
  }

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

  isSecure(): boolean {
    return this.value.startsWith('https://');
  }

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

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