import { MediaUrl } from '../../../../../core/media/domain/value-objects/MediaUrl';

describe('MediaUrl', () => {
  it('creates from valid http/https URLs', () => {
    expect(MediaUrl.create('http://example.com').value).toBe('http://example.com');
    expect(MediaUrl.create('https://example.com/path').value).toBe('https://example.com/path');
  });

  it('creates from data URIs', () => {
    const url = 'data:image/jpeg;base64,AAA';
    expect(MediaUrl.create(url).value).toBe(url);
  });

  it('creates from root-relative paths', () => {
    expect(MediaUrl.create('/images/avatar.png').value).toBe('/images/avatar.png');
  });

  it('rejects empty or whitespace URLs', () => {
    expect(() => MediaUrl.create('')).toThrow();
    expect(() => MediaUrl.create('   ')).toThrow();
  });

  it('rejects unsupported schemes', () => {
    expect(() => MediaUrl.create('ftp://example.com/file')).toThrow();
    expect(() => MediaUrl.create('mailto:user@example.com')).toThrow();
  });

  it('implements value-based equality', () => {
    const a = MediaUrl.create('https://example.com/a.png');
    const b = MediaUrl.create('https://example.com/a.png');
    const c = MediaUrl.create('https://example.com/b.png');

    expect(a.equals(b)).toBe(true);
    expect(a.equals(c)).toBe(false);
  });
});