"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;
function _graphqlTag() {
  const data = require("graphql-tag");
  _graphqlTag = function () {
    return data;
  };
  return data;
}
function _workspace() {
  const data = require("./workspace");
  _workspace = function () {
    return data;
  };
  return data;
}
var _default = (workspace, graphql) => {
  return {
    typeDefs: (0, _graphqlTag().gql)`
      type ModifyInfo {
        # is the component modified.
        hasModifiedFiles: Boolean

        # the component has Modified Dependencies
        hasModifiedDependencies: Boolean
      }

      type ComponentStatus {
        # component is pending to be tagged automatically.
        modifyInfo: ModifyInfo

        # is the new component new.
        isNew: Boolean

        # is the component deleted from the workspace.
        isDeleted: Boolean

        # is the component staged.
        isStaged: Boolean

        # does the component exists in the workspace.
        isInWorkspace: Boolean

        # does the component exists in the scope.
        isInScope: Boolean

        # does the component is outdated (pending for update).
        isOutdated: Boolean
      }

      extend type Component {
        status: ComponentStatus
      }

      type Issue {
        type: String!
        description: String!
        solution: String
        data: String
      }

      extend type Component {
        # the count of errors in component in workspace
        issuesCount: Int
        issues: [Issue]
      }

      type Workspace {
        name: String
        path: String
        icon: String
        components(offset: Int, limit: Int): [Component]
        getComponent(id: String!): Component
      }

      type Subscription {
        componentAdded: ComponentAdded
        componentChanged: ComponentChanged
        componentRemoved: ComponentRemoved
      }

      type ComponentAdded {
        component: Component
      }

      type ComponentChanged {
        component: Component
      }

      type ComponentRemoved {
        componentIds: [ComponentID]
      }

      type Query {
        workspace: Workspace
      }
    `,
    resolvers: {
      Subscription: {
        componentAdded: {
          subscribe: () => graphql.pubsub.asyncIterator(_workspace().ComponentAdded)
        },
        componentChanged: {
          subscribe: () => graphql.pubsub.asyncIterator(_workspace().ComponentChanged)
        },
        componentRemoved: {
          subscribe: () => graphql.pubsub.asyncIterator(_workspace().ComponentRemoved)
        }
      },
      Component: {
        status: async wsComponent => {
          return wsComponent.getStatus();
        },
        issuesCount: wsComponent => {
          return wsComponent.getIssues()?.count || 0;
        },
        issues: wsComponent => {
          return wsComponent.getIssues()?.toObjectWithDataAsString();
        }
      },
      Workspace: {
        path: ws => ws.path,
        name: ws => ws.name,
        icon: ws => ws.icon,
        components: async (ws, {
          offset,
          limit
        }) => {
          return ws.list({
            offset,
            limit
          });
        },
        getComponent: async (ws, {
          id
        }) => {
          try {
            const componentID = await ws.resolveComponentId(id);
            const component = await ws.get(componentID);
            return component;
          } catch (error) {
            return null;
          }
        }
      },
      Query: {
        workspace: () => workspace
      }
    }
  };
};
exports.default = _default;

//# sourceMappingURL=workspace.graphql.js.map