import { Property, createAction } from '@activepieces/pieces-framework';
import { mondayAuth } from '../auth';
import { makeClient, mondayCommon } from '../common';

export const createGroupAction = createAction({
  auth: mondayAuth,
  name: 'monday_create_group',
  displayName: 'Create Group',
  description: 'Creates a new group in board.',
  audience: 'both',
  aiMetadata: { description: 'Creates a new group (section that holds items) on a monday.com board. Use to organize items under a named section before adding them. Not idempotent: each call creates a separate group even with the same name.', idempotent: false },
  props: {
    workspace_id: mondayCommon.workspace_id(true),
    board_id: mondayCommon.board_id(true),
    group_name: Property.ShortText({
      displayName: 'Group Name',
      required: true,
    }),
  },
  async run(context) {
    const { board_id, group_name } = context.propsValue;

    const client = makeClient(context.auth);
    return await client.createGroup({
      boardId: board_id as string,
      groupName: group_name as string,
    });
  },
});
