import { IMocks } from 'apollo-server';


// due to some reason, we need to explicitly add `__typename` in the return output.
// https://github.com/apollographql/graphql-tools/issues/1068

export const mock: IMocks = {

  ISettingsSubject: () => ({
    __resolveType(subject, context, info) {
      if (subject.settingsURL.startsWith('file://')) {
        return 'FolderSettings';
      }
      if (subject.settingsURL === 'default') {
        return 'GlobalSettings';
      }
      if (subject.settingsURL === 'user') {
        return 'IUserSettings';
      }
      return null;
    },
  }),
  FolderSettings: () => ({

  }),
  IUserSettings: () => ({
    latestSettings: {
      contents: 'hi mariam',
    },
    viewerCanAdminister: true,
  }),
  GlobalSettings: () => ({
    latestSettings: {
      contents: 'hi mariam',
    },
    viewerCanAdminister: true,
  }),
  Query: () => ({
    viewerSettings: () => ({
      subjects: [
        {
          __typename: 'IUserSettings',
          id: 'a',
          settingsURL: 'user',
          latestSettings: { id: 1, contents: '{"a":1}' },
          viewerCanAdminister: true,
        },
        {
          __typename: 'GlobalSettings',
          id: 'b',
          settingsURL: 'default',
          latestSettings: {
            contents: 'hi mariam',
          },
          viewerCanAdminister: true,
        },
        {
          __typename: 'FolderSettings',
          id: 'c',
          settingsURL: 'file:///test',
          latestSettings: {
            contents: 'hi mariam',
          },
          viewerCanAdminister: true,
        },
      ],
      final:
        // tslint:disable-next-line:max-line-length
        "{'files':{'trimTrailingWhitespace':false,'autoSave':'off','exclude':{'** /.git':true,'**/.svn':true,'** /.hg':true,'**/CVS':true,'** /.DS_Store':true},'associations':{},'encoding':'utf8','autoGuessEncoding':false,'eol':'\\n','insertFinalNewline':false,'autoSaveDelay':1000,'watcherExclude':{'**/.git/**':true,'**/node_modules/**':true},'hotExit':'onExit','useExperimentalFileWatcher':false,'defaultLanguage':' '}}",
    }),
  }),
};
