export type RunState = {
  uid: string;
  readyToFinish: boolean;
  status: string;
  createdAt: string;
  completedAt: string | null;
  currentArticle: {
    uid: string;
  };
};

export type ArticleWithProperties = {
  uid: string;
  name: string;
  bodyMarkdown: string;
  hasAssignees: boolean;
  isAssigned: boolean;
  createdAt: string;
  updatedAt: string;
  properties: Array<{
    propId: string;
    propName: string;
    propCode: string;
    propType: string;
    required: boolean;
    readOnly: boolean;
  }>;
};

export type GetArticleWithPropertiesQuery = {
  node: {
    __typename: 'Article';
    uid: string;
  } & ArticleWithProperties;
};

export type RunProcessMutation = {
  runProcess: {
    runState: {
      uid: string;
      readyToFinish: boolean;
      status: string;
      createdAt: string;
      completedAt: string | null;
    };
    nextArticle: ArticleWithProperties;
    success: boolean;
    errors: Array<{
      attribute: string;
      message: string;
      error: string;
    }>;
  };
};

export type RunProcessMutationVariables = {
  bookUid: string;
  propertyValues: Array<{
    propId: string;
    value: string | null;
  }>;
};

export type FinishProcessMutation = {
  finishProcess: {
    runState: {
      uid: string;
      readyToFinish: boolean;
      status: string;
      createdAt: string;
      completedAt: string | null;
    };
    finishMessage: string | null;
    success: boolean;
    errors: Array<{
      attribute: string;
      message: string;
    }>;
  };
};

export type FinishProcessMutationVariables = {
  uid: string;
};

export type UpdateRunStateMutation = {
  updateRunState: {
    runState: {
      uid: string;
      readyToFinish: boolean;
      status: string;
      createdAt: string;
      completedAt: string | null;
    };
    nextArticle: ArticleWithProperties;
    success: boolean;
    errors: Array<{
      attribute: string;
      message: string;
      error: string;
    }>;
  };
};

export type UpdateRunStateMutationVariables = {
  uid: string;
  articleUid: string;
  propertyValues: Array<{
    propId: string;
    value: string | null;
  }>;
};

type Article = {
  uid: string;
  name: string;
  slug: string;
  id: string;
  bodyMarkdown: string;
  createdAt: string;
  updatedAt: string;
  allCategories: Array<{
    uid: string;
    name: string;
  }>;
  folder: {
    uid: string;
    name: string;
  };
  book: {
    uid: string;
    name: string;
    bookType: string;
  };
};

export type GetArticleQuery = {
  node: {
    __typename: 'Article';
  } & Article;
};

export type GetArticleByPathQuery = {
  book: {
    article: Article;
  };
};

export type GetBookQuery = {
  node: {
    __typename: 'Book';
    uid: string;
    name: string;
    description: string | null;
    bookType: string;
    rootFolder: {
      uid: string;
    };
    initialArticle: {
      uid: string;
      name: string;
      bodyMarkdown: string;
    };
    workspace: {
      uid: string;
      name: string;
      description: string | null;
    };
  };
};

export type ContentFolderNode = {
  __typename: 'ContentFolderNode';
  nodeType: string;
  uid: string;
  name: string;
};

export type ContentArticleNode = {
  __typename: 'ContentArticleNode';
  nodeType: string;
  uid: string;
  name: string;
};

export type ContentNode = ContentFolderNode | ContentArticleNode;

export type GetFolderQuery = {
  node: {
    __typename: 'Folder';
    uid: string;
    name: string;
    ancestors: Array<{
      uid: string;
      name: string;
    }>;
    children: {
      nodes: Array<ContentNode>;
    };
  };
};

export type GetBookWithRunStatesQuery = {
  node: {
    __typename: 'Book';
    uid: string;
    name: string;
    bookType: string;
    initialArticle: {
      uid: string;
    };
    runStates: {
      nodes: Array<RunState>;
    };
  };
};

export type GetBookWithRunStateQuery = {
  node: {
    __typename: 'Book';
    uid: string;
    name: string;
    bookType: string;
    initialArticle: {
      uid: string;
    };
    runState: RunState | null;
  };
};

export type CreateArticleMutation = {
  createArticle: {
    article: {
      uid: string;
      id: string;
    };
    success: boolean;
    errors: Array<{
      attribute: string;
      message: string;
    }>;
  };
};

export type CreateArticleMutationVariables = {
  bookUid: string;
  name: string;
  bodyMarkdown?: string | null;
  categoryUids?: Array<string> | null;
};

export type UpdateArticleMutation = {
  updateArticle: {
    article: {
      uid: string;
      id: string;
    };
    success: boolean;
    errors: Array<{
      attribute: string;
      message: string;
    }>;
  };
};

export type UpdateArticleMutationVariables = {
  uid: string;
  name?: string | null;
  bodyMarkdown?: string | null;
  categoryUids?: Array<string> | null;
};
