/**
 * Value Object: FileSha256
 *
 * Encapsulates a SHA-256 hash string for file integrity verification.
 * The hash must be a valid 64-character lowercase hexadecimal string.
 */
export class FileSha256 {
  private static readonly SHA256_REGEX = /^[a-f0-9]{64}$/;

  private readonly value: string;

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

  static create(value: string): FileSha256 {
    const normalized = value.toLowerCase();
    if (!FileSha256.SHA256_REGEX.test(normalized)) {
      throw new Error(
        `Invalid SHA-256 hash: "${value}". Must be a 64-character hex string.`,
      );
    }
    return new FileSha256(normalized);
  }

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

  matches(other: FileSha256): boolean {
    return this.value === other.value;
  }

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

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