import {
  listTags,
  createTag,
  updateTag,
  deleteTag,
  listTagsForAccount,
  createTagForAccount,
} from '@wix/bex-utils/@wix/ambassador-os-tags-v1-tag/http';
import { Tag } from '@wix/bex-utils/@wix/ambassador-os-tags-v1-tag/types';

export const aTag = (overrides: Partial<Tag> = {}): Tag => {
  return {
    createdDate: new Date(),
    ...overrides,
  } as Tag;
};

export const aTagsArray = (count: number) =>
  Array.from({ length: count }, (_, index) =>
    aTag({ id: String(index), name: `Tag ${index}` }),
  );

export const tags = aTagsArray(2);

export function tagsServiceMocks(
  whenRequest: typeof import('@wix/http-client-testkit/client').whenRequest,
) {
  return {
    mocks: [
      whenRequest(listTags)
        .reply(200, async () => {
          const data = {
            tags,
          };

          return data;
        })
        .persist(),
      whenRequest(createTag)
        .reply(200, async ({ tag }) => {
          return { tag };
        })
        .persist(),
      whenRequest(updateTag)
        .reply(200, async (tag) => {
          return tag;
        })
        .persist(),
      whenRequest(deleteTag)
        .reply(200, () => {})
        .persist(),
      whenRequest(listTagsForAccount)
        .reply(200, async () => {
          const data = {
            tags,
          };

          return data;
        })
        .persist(),
      whenRequest(createTagForAccount)
        .reply(200, async ({ tag }) => {
          return { tag };
        })
        .persist(),
    ] as import('@wix/http-client-testkit').AnyScenario[],
  };
}
