import { describe, expect, it } from 'vitest';
import { ManualClock, OfficeRuntime, renderScenario } from '../src/index.ts';
import { demoOffice } from './helpers.ts';

const office = demoOffice();
const hello = (o: typeof office, portraits?: boolean) => new OfficeRuntime({ office: o, clock: new ManualClock(), portraits }).hello();

describe('портреты в hello.avatarKit (спека диалоговых окон 2.4)', () => {
  it('флаг portraits — avatarKit.portraits: четыре шаблона как в каталоге', () => {
    expect(hello(office, true).avatarKit.portraits).toEqual({
      skins: 'modern-ui/16x16/Portrait_Generator/Skins/PG_Skin_{body:0}.png',
      eyes: 'modern-ui/16x16/Portrait_Generator/Eyes/PG_Eyes_{eyes}.png',
      hairs: 'modern-ui/16x16/Portrait_Generator/Hairstyles/PG_Hairstyle_{model}_{color:0}.png',
      accessories: 'modern-ui/16x16/Portrait_Generator/Accessories/PG_Accessory_{model}_{name}_{color:0}.png',
    });
  });

  it('без флага — поля нет', () => {
    expect(hello(office).avatarKit.portraits).toBeUndefined();
    expect(hello(office, false).avatarKit.portraits).toBeUndefined();
  });

  it('без раздела portraits в каталоге — поля нет и с флагом', () => {
    const characters = office.bundle.catalog.characters;
    const bare = { ...office, bundle: { ...office.bundle, catalog: { ...office.bundle.catalog, characters: { ...characters, portraits: undefined } } } };
    expect(hello(bare, true).avatarKit.portraits).toBeUndefined();
  });

  it('тестовый режим: флаг передаётся в renderScenario', async () => {
    const q = { scenario: 'morning', t: '0', seed: '1' };
    expect((await renderScenario(office, q, { portraits: true }))[0].avatarKit.portraits?.skins).toContain('PG_Skin_{body:0}');
    expect((await renderScenario(office, q))[0].avatarKit.portraits).toBeUndefined();
  });
});
