import { createAction, Property } from '@activepieces/pieces-framework';
import { enrichlayerAuth } from '../auth';
import { enrichlayerApiCall } from '../common/client';
import { ENDPOINTS } from '../common/constants';

export const getPersonalContact = createAction({
  name: 'get_personal_contact',
  auth: enrichlayerAuth,
  displayName: 'Look Up Personal Contact Numbers',
  description:
    'Find personal phone numbers from a social media profile (1 credit per number returned)',
  audience: 'both',
  aiMetadata: {
    description:
      "Find a person's personal phone numbers from one social profile URL (professional-network, Twitter/X, or Facebook — supply exactly one). Read-only and safe to retry. Use when you have a profile link and need phone contact details; the email counterpart is Look Up Personal Email.",
    idempotent: true,
  },
  props: {
    profile_url: Property.ShortText({
      displayName: 'Profile URL',
      description:
        'Professional network profile URL. Provide only one of Profile URL, Twitter URL, or Facebook URL.',
      required: false,
    }),
    twitter_profile_url: Property.ShortText({
      displayName: 'Twitter/X Profile URL',
      description:
        'Twitter/X profile URL (e.g., https://x.com/enrichlayer). Provide only one of Profile URL, Twitter URL, or Facebook URL.',
      required: false,
    }),
    facebook_profile_url: Property.ShortText({
      displayName: 'Facebook Profile URL',
      description:
        'Facebook profile URL (e.g., https://www.facebook.com/zuck). Provide only one of Profile URL, Twitter URL, or Facebook URL.',
      required: false,
    }),
    page_size: Property.ShortText({
      displayName: 'Page Size',
      description:
        'Maximum numbers returned (0 = no limit, default: 0)',
      required: false,
    }),
  },
  async run(context) {
    return await enrichlayerApiCall(
      context.auth.secret_text as string,
      ENDPOINTS.PERSONAL_CONTACT,
      {
        profile_url: context.propsValue.profile_url,
        twitter_profile_url: context.propsValue.twitter_profile_url,
        facebook_profile_url: context.propsValue.facebook_profile_url,
        page_size: context.propsValue.page_size,
      },
    );
  },
});
