import { createCustomApiCallAction } from '@activepieces/pieces-common';
import { createPiece } from '@activepieces/pieces-framework';
import { PieceCategory } from '@activepieces/pieces-framework';
import { githubAuthHelpers, GithubAuthValue } from './lib/common/auth-helpers';
import { githubCreateIssueAction } from './lib/actions/create-issue';
import { githubUnlockIssueAction } from './lib/actions/unlock-issue';
import { githubTriggers } from './lib/trigger';
import { githubGetIssueInformation } from './lib/actions/get-issue-information';
import { githubCreateCommentOnAIssue } from './lib/actions/create-comment-on-a-issue';
import { githubLockIssueAction } from './lib/actions/lock-issue';
import { githubRawGraphqlQuery } from './lib/actions/raw-graphql-query';
import { githubCreatePullRequestReviewCommentAction } from './lib/actions/create-pull-request-review-comment';
import { githubCreateCommitCommentAction } from './lib/actions/create-commit-comment';
import { githubCreateDiscussionCommentAction } from './lib/actions/create-discussion-comment';
import { githubAddLabelsToIssueAction } from './lib/actions/add-labels-to-issue';
import { githubCreateBranchAction } from './lib/actions/create-branch';
import { githubDeleteBranchAction } from './lib/actions/delete-branch';
import { githubUpdateIssueAction } from './lib/actions/update-issue';
import { githubCreateGistAction } from './lib/actions/create-gist';

import { githubFindBranchAction } from './lib/actions/find-branch';
import { githubFindIssueAction } from './lib/actions/find-issue';
import { githubFindUserAction } from './lib/actions/find-user';

import { githubAuth } from './lib/auth';

export const github = createPiece({
  displayName: 'GitHub',
  description:
    'Developer platform that allows developers to create, store, manage and share their code',

  minimumSupportedRelease: '0.30.0',
  logoUrl: 'https://cdn.activepieces.com/pieces/github.png',
  categories: [PieceCategory.DEVELOPER_TOOLS],
  auth: githubAuth,
  actions: [
    githubCreateIssueAction,
    githubGetIssueInformation,
    githubCreateCommentOnAIssue,
    githubLockIssueAction,
    githubUnlockIssueAction,
    githubRawGraphqlQuery,
    githubCreatePullRequestReviewCommentAction,
    githubCreateCommitCommentAction,
    githubCreateDiscussionCommentAction,
    githubAddLabelsToIssueAction,
    githubCreateBranchAction,
    githubDeleteBranchAction,
    githubUpdateIssueAction,
    githubFindBranchAction,
    githubFindIssueAction,
    githubFindUserAction,
    githubCreateGistAction,
    createCustomApiCallAction({
      baseUrl: () => 'https://api.github.com',
      auth: githubAuth,
      authMapping: async (auth) => ({
        Authorization: `Bearer ${await githubAuthHelpers.getBearerToken(
          auth as GithubAuthValue
        )}`,
      }),
    }),
  ],
  authors: [
    'kishanprmr',
    'MoShizzle',
    'AbdulTheActivePiecer',
    'khaledmashaly',
    'abuaboud',
    'tintinthedev',
    'murex971',
    'sanket-a11y',
  ],
  triggers: githubTriggers,
});
