import { describe, it, expect } from 'vitest';

import {
  extractPromotionIntent,
  isBerthPromotable,
} from '@/lib/services/website-intake-promote.service';

describe('extractPromotionIntent', () => {
  it('detects a specific berth on a berth_inquiry', () => {
    expect(extractPromotionIntent('berth_inquiry', { first_name: 'Jane', berth: 'A1' })).toEqual({
      hasSpecificBerth: true,
      mooringNumber: 'A1',
    });
  });

  it('returns no berth for a berth_inquiry with no mooring', () => {
    expect(extractPromotionIntent('berth_inquiry', { first_name: 'Jane' })).toEqual({
      hasSpecificBerth: false,
      mooringNumber: null,
    });
  });

  it('ignores residence / contact kinds entirely', () => {
    expect(extractPromotionIntent('residence_inquiry', { berth: 'A1' })).toEqual({
      hasSpecificBerth: false,
      mooringNumber: null,
    });
    expect(extractPromotionIntent('contact_form', { berth: 'A1' })).toEqual({
      hasSpecificBerth: false,
      mooringNumber: null,
    });
  });
});

describe('isBerthPromotable', () => {
  it('only an exactly-available berth is promotable', () => {
    expect(isBerthPromotable('available')).toBe(true);
  });
  it('under_offer / sold / unknown / null are NOT promotable (never stomp)', () => {
    expect(isBerthPromotable('under_offer')).toBe(false);
    expect(isBerthPromotable('sold')).toBe(false);
    expect(isBerthPromotable('something')).toBe(false);
    expect(isBerthPromotable(null)).toBe(false);
    expect(isBerthPromotable(undefined)).toBe(false);
  });
});
