import {
  Account,
  Announcement,
  Company,
  Conversation,
  ConversationPrompt,
  Document,
  Feedback,
} from './data';

describe('ConversationPrompt', () => {
  it('uses defaults when constructed with no args', () => {
    const prompt = new ConversationPrompt();
    expect(prompt.id).toBeUndefined();
    expect(prompt.message).toBe('');
    expect(prompt.user_created).toBe(false);
    expect(prompt.created_timestamp).toBeInstanceOf(Date);
  });

  it('hydrates from initializer', () => {
    const created = new Date('2024-01-01');
    const prompt = new ConversationPrompt({
      id: 7,
      message: 'hello',
      user_created: true,
      created_timestamp: created,
    });
    expect(prompt.id).toBe(7);
    expect(prompt.message).toBe('hello');
    expect(prompt.user_created).toBe(true);
    expect(prompt.created_timestamp).toEqual(created);
  });
});

describe('Company', () => {
  it('uses defaults when constructed with no args', () => {
    const company = new Company();
    expect(company.id).toBeUndefined();
    expect(company.name).toBe('');
    expect(company.state).toBe('');
    expect(company.zipcode).toBeUndefined();
    expect(company.address).toBe('');
  });

  it('hydrates from initializer', () => {
    const company = new Company({
      id: 1,
      name: 'Acme',
      state: 'CA',
      zipcode: 90210,
      address: '1 Main St',
    });
    expect(company.id).toBe(1);
    expect(company.name).toBe('Acme');
    expect(company.state).toBe('CA');
    expect(company.zipcode).toBe(90210);
    expect(company.address).toBe('1 Main St');
  });
});

describe('Conversation', () => {
  it('uses defaults when constructed with no args', () => {
    const conversation = new Conversation();
    expect(conversation.id).toBeUndefined();
    expect(conversation.title).toBe('');
    expect(conversation.conversationDetail).toEqual([]);
    expect(conversation.account).toBeUndefined();
  });

  it('hydrates from initializer', () => {
    const detail = [new ConversationPrompt({ id: 1, message: 'hi' })];
    const account = new Account({ email: 'a@b.com' });
    const conversation = new Conversation({
      id: 42,
      title: 'Chat',
      conversationDetail: detail,
      account,
    });
    expect(conversation.id).toBe(42);
    expect(conversation.title).toBe('Chat');
    expect(conversation.conversationDetail).toEqual(detail);
    expect(conversation.account).toEqual(account);
  });
});

describe('Announcement', () => {
  it('uses defaults when constructed with no args', () => {
    const announcement = new Announcement();
    expect(announcement.status).toBe('default');
    expect(announcement.message).toBe('');
  });

  it('hydrates from initializer', () => {
    const announcement = new Announcement({
      status: 'info',
      message: 'Welcome',
    });
    expect(announcement.status).toBe('info');
    expect(announcement.message).toBe('Welcome');
  });
});

describe('Document', () => {
  it('uses defaults when constructed with no args', () => {
    const doc = new Document();
    expect(doc.id).toBe(0);
    expect(doc.name).toBe('');
    expect(doc.file).toBe('');
    expect(doc.date_uploaded).toBe('');
    expect(doc.active).toBe(false);
    expect(doc.processed).toBe(false);
  });

  it('hydrates from initializer', () => {
    const doc = new Document({
      id: 9,
      name: 'report.pdf',
      file: '/files/report.pdf',
      date_uploaded: '2024-06-01',
      active: true,
      processed: true,
    });
    expect(doc.id).toBe(9);
    expect(doc.name).toBe('report.pdf');
    expect(doc.file).toBe('/files/report.pdf');
    expect(doc.date_uploaded).toBe('2024-06-01');
    expect(doc.active).toBe(true);
    expect(doc.processed).toBe(true);
  });
});

describe('Feedback', () => {
  it('uses defaults when constructed with no args', () => {
    const feedback = new Feedback();
    expect(feedback.id).toBe(0);
    expect(feedback.title).toBe('');
    expect(feedback.status).toBe('');
    expect(feedback.text).toBe('');
    expect(feedback.category).toBe('');
  });

  it('hydrates from initializer', () => {
    const feedback = new Feedback({
      id: 3,
      title: 'Bug',
      status: 'open',
      text: 'Broken button',
      category: 'ui',
    });
    expect(feedback.id).toBe(3);
    expect(feedback.title).toBe('Bug');
    expect(feedback.status).toBe('open');
    expect(feedback.text).toBe('Broken button');
    expect(feedback.category).toBe('ui');
  });
});

describe('Account', () => {
  it('uses defaults when constructed with no args', () => {
    const account = new Account();
    expect(account.email).toBe('');
    expect(account.first_name).toBe('');
    expect(account.last_name).toBe('');
    expect(account.role).toBeUndefined();
    expect(account.company).toBeUndefined();
    expect(account.is_company_manager).toBe(false);
    expect(account.has_password).toBe(false);
    expect(account.is_active).toBe(false);
    expect(account.has_signed_tos).toBe(false);
  });

  it('hydrates from initializer', () => {
    const company = new Company({ id: 1, name: 'Acme' });
    const account = new Account({
      email: 'user@example.com',
      first_name: 'Jane',
      last_name: 'Doe',
      role: 'admin',
      company,
      is_company_manager: true,
      has_password: true,
      is_active: true,
      has_signed_tos: true,
    });
    expect(account.email).toBe('user@example.com');
    expect(account.first_name).toBe('Jane');
    expect(account.last_name).toBe('Doe');
    expect(account.role).toBe('admin');
    expect(account.company).toEqual(company);
    expect(account.is_company_manager).toBe(true);
    expect(account.has_password).toBe(true);
    expect(account.is_active).toBe(true);
    expect(account.has_signed_tos).toBe(true);
  });
});
