import { describe, it, expect, beforeEach } from 'vitest';
import { AuthSessionPresenter } from './AuthSessionPresenter';
import { User } from '@core/identity/domain/entities/User';
import { UserId } from '@core/identity/domain/value-objects/UserId';
import { PasswordHash } from '@core/identity/domain/value-objects/PasswordHash';

describe('AuthSessionPresenter', () => {
  let presenter: AuthSessionPresenter;

  beforeEach(() => {
    presenter = new AuthSessionPresenter();
  });

  it('maps user result into response model', () => {
    const user = User.create({
      id: UserId.fromString('user-1'),
      displayName: 'Test User',
      email: 'user@example.com',
      passwordHash: PasswordHash.fromHash('hash'),
    });

    presenter.present({ user } as unknown as Parameters<AuthSessionPresenter['present']>[0]);

    expect(presenter.getResponseModel()).toEqual({
      userId: 'user-1',
      email: 'user@example.com',
      displayName: 'Test User',
    });

    expect(presenter.responseModel).toEqual({
      userId: 'user-1',
      email: 'user@example.com',
      displayName: 'Test User',
    });
  });

  it('throws when not presented', () => {
    expect(() => presenter.getResponseModel()).toThrow('Presenter not presented');
    expect(() => presenter.responseModel).toThrow('Presenter not presented');
  });

  it('reset clears model', () => {
    const user = User.create({
      id: UserId.fromString('user-1'),
      displayName: 'Test User',
      email: 'user@example.com',
      passwordHash: PasswordHash.fromHash('hash'),
    });

    presenter.present({ user } as unknown as Parameters<AuthSessionPresenter['present']>[0]);
    presenter.reset();

    expect(() => presenter.responseModel).toThrow('Presenter not presented');
  });
});
