import { describe, test, expect } from "bun:test";
import type {
  CWOpportunity,
  CWForecastItem,
  CWForecast,
  CWForecastRevenueSummary,
  CWOpportunityNote,
  CWOpportunityNoteCreate,
  CWOpportunityNoteUpdate,
  CWOpportunityContact,
  CWCustomField,
} from "../../src/modules/cw-utils/opportunities/opportunity.types";

describe("opportunity.types", () => {
  test("CWForecastItem has all required fields", () => {
    const item: CWForecastItem = {
      id: 1,
      forecastDescription: "Test",
      opportunity: { id: 100, name: "Opp" },
      quantity: 5,
      status: { id: 1, name: "Won" },
      productDescription: "Widget",
      productClass: "Product",
      revenue: 1000,
      cost: 500,
      margin: 500,
      percentage: 100,
      includeFlag: true,
      quoteWerksQuantity: 0,
      forecastType: "Product",
      linkFlag: false,
      recurringRevenue: 0,
      recurringCost: 0,
      cycles: 0,
      recurringFlag: false,
      sequenceNumber: 1,
      subNumber: 0,
      taxableFlag: true,
    };
    expect(item.id).toBe(1);
    expect(item.forecastDescription).toBe("Test");
    expect(item.quantity).toBe(5);
    expect(item.revenue).toBe(1000);
    expect(item.cost).toBe(500);
    expect(item.margin).toBe(500);
  });

  test("CWForecast has forecastItems and revenue summaries", () => {
    const summary: CWForecastRevenueSummary = {
      id: 1,
      revenue: 1000,
      cost: 500,
      margin: 500,
      percentage: 50,
    };

    const forecast: CWForecast = {
      id: 100,
      forecastItems: [],
      productRevenue: summary,
      serviceRevenue: summary,
      agreementRevenue: summary,
      timeRevenue: summary,
      expenseRevenue: summary,
      forecastRevenueTotals: summary,
      inclusiveRevenueTotals: summary,
      recurringTotal: 0,
      wonRevenue: summary,
      lostRevenue: summary,
      openRevenue: summary,
      otherRevenue1: summary,
      otherRevenue2: summary,
      salesTaxRevenue: 50,
      forecastTotalWithTaxes: 1050,
      expectedProbability: 75,
      taxCode: { id: 1, name: "Default" },
      billingTerms: { id: 1, name: "Net 30" },
      currency: {
        id: 1,
        symbol: "$",
        currencyCode: "USD",
        name: "US Dollar",
      },
    };

    expect(forecast.id).toBe(100);
    expect(forecast.salesTaxRevenue).toBe(50);
    expect(forecast.currency.currencyCode).toBe("USD");
  });

  test("CWOpportunityNoteCreate has required text field", () => {
    const note: CWOpportunityNoteCreate = {
      text: "Hello",
    };
    expect(note.text).toBe("Hello");
  });

  test("CWOpportunityNoteUpdate allows partial fields", () => {
    const update: CWOpportunityNoteUpdate = {
      text: "Updated text",
    };
    expect(update.text).toBe("Updated text");
    expect(update.flagged).toBeUndefined();
  });

  test("CWCustomField is exported and usable", () => {
    const field: CWCustomField = {
      id: 1,
      caption: "Custom Field",
      type: "Text",
      entryMethod: "EntryField",
      numberOfDecimals: 0,
      value: "test value",
    };
    expect(field.caption).toBe("Custom Field");
  });
});
