import { describe, test, expect } from "bun:test";
import type {
  CWActivity,
  CWActivitySummary,
  CWActivityCustomField,
  CWActivityInfo,
  CWCreateActivity,
  CWUpdateActivity,
  CWPatchOperation,
} from "../../src/modules/cw-utils/activities/activity.types";

describe("activity.types", () => {
  test("CWActivity type has all required fields", () => {
    const activity: CWActivity = {
      id: 1,
      name: "Test Call",
      type: { id: 1, name: "Call" },
      company: { id: 100, identifier: "TestCo", name: "Test Company" },
      contact: { id: 200, name: "John" },
      phoneNumber: "555-1234",
      email: "test@test.com",
      status: { id: 1, name: "Open" },
      opportunity: { id: 300, name: "Opp" },
      ticket: { id: 0, name: "" },
      agreement: { id: 0, name: "" },
      campaign: { id: 0, name: "" },
      notes: "Some notes",
      dateStart: "2026-01-01T09:00:00Z",
      dateEnd: "2026-01-01T10:00:00Z",
      assignTo: { id: 10, identifier: "jroberts", name: "John Roberts" },
      scheduleStatus: { id: 1, name: "Firm" },
      reminder: { id: 1, name: "15 min" },
      where: { id: 1, name: "Office" },
      notifyFlag: false,
      mobileGuid: "guid-123",
      currency: { id: 1, name: "USD" },
      customFields: [],
      _info: {
        lastUpdated: "2026-01-01T12:00:00Z",
        updatedBy: "admin",
        dateEntered: "2026-01-01T08:00:00Z",
        enteredBy: "admin",
      },
    };

    expect(activity.id).toBe(1);
    expect(activity.name).toBe("Test Call");
    expect(activity.assignTo.identifier).toBe("jroberts");
  });

  test("CWCreateActivity allows partial fields", () => {
    const create: CWCreateActivity = {
      name: "New Activity",
      opportunity: { id: 300 },
    };
    expect(create.name).toBe("New Activity");
    expect(create.company).toBeUndefined();
  });

  test("CWPatchOperation has op, path, value", () => {
    const op: CWPatchOperation = {
      op: "replace",
      path: "name",
      value: "Updated Name",
    };
    expect(op.op).toBe("replace");
    expect(op.path).toBe("name");
  });

  test("CWActivitySummary is lightweight", () => {
    const summary: CWActivitySummary = {
      id: 42,
      _info: { lastUpdated: "2026-01-01T00:00:00Z" },
    };
    expect(summary.id).toBe(42);
  });

  test("CWActivityCustomField has expected shape", () => {
    const field: CWActivityCustomField = {
      id: 1,
      caption: "Project Code",
      type: "Text",
      entryMethod: "EntryField",
      numberOfDecimals: 0,
      value: "PRJ-001",
    };
    expect(field.caption).toBe("Project Code");
  });
});
