import type { FieldSchema } from '@zyphon/provider-contracts';

type FieldOpts = Partial<Omit<FieldSchema, 'key' | 'label'>>;

export function tx(key: string, label: string, opts: FieldOpts = {}): FieldSchema {
  return {
    key,
    label,
    type: opts.type ?? 'text',
    required: opts.optional ? false : opts.required !== false,
    ...opts,
  };
}

export function sx(key: string, label: string, opts: FieldOpts = {}): FieldSchema {
  return {
    key,
    label,
    type: opts.type ?? 'secret',
    required: opts.optional ? false : opts.required !== false,
    ...opts,
  };
}

export function sl(
  key: string,
  label: string,
  options: Array<{ value: string; label: string }>,
  opts: FieldOpts = {},
): FieldSchema {
  return {
    key,
    label,
    type: 'select',
    options,
    required: opts.optional ? false : opts.required !== false,
    ...opts,
  };
}

export const FROM_EMAIL = tx('from', 'Send emails as', {
  placeholder: 'noreply@company.com',
  validator: 'email',
});
