import type {
  AccountPayableDistributionLine,
  AccountPayableDocument,
  AccountPayableDocumentLine,
  AccountPayableDueScheduleLine,
  Schema,
} from "../lib/types";
import type {
  Account,
  Company,
  Currency,
  Partner,
  PurchaseOrderLineForMatching,
  PurchaseReceiptQuantityForMatching,
} from "./moduleMocks";

const createdAt = new Date("2024-01-01T00:00:00.000Z");

export const baseCompany = {
  id: "company-1",
  status: "ACTIVE",
  legalName: "Test Corp",
  baseCurrencyId: "currency-1",
  taxId: null,
  registrationNumber: null,
  street: "123 Main St",
  city: "New York",
  state: "NY",
  postalCode: "10001",
  country: "US",
  createdAt,
  updatedAt: null,
} as const satisfies Company;

export const baseBusinessPartner = {
  id: "business-partner-1",
  companyId: "company-1",
  name: "Vendor One",
  status: "ACTIVE",
  type: "ORGANIZATION",
  preferredCurrencyId: null,
  createdAt,
  updatedAt: null,
} as const satisfies Partner;

export const baseCurrency = {
  id: "currency-1",
  code: "USD",
  status: "ACTIVE",
  symbol: "$",
  name: "US Dollar",
  decimalPlaces: 2,
  isBaseCurrency: true,
  createdAt,
  updatedAt: null,
} as const satisfies Currency;

export const expenseAccount = {
  id: "account-expense",
  code: "5000",
  name: "Cost of Goods Sold",
  accountType: "EXPENSE",
  companyId: baseCompany.id,
  status: "ACTIVE",
  createdAt,
  updatedAt: null,
} as const satisfies Account;

export const payableAccount = {
  id: "account-payable",
  code: "2100",
  name: "Accounts Payable Control",
  accountType: "LIABILITY",
  companyId: baseCompany.id,
  status: "ACTIVE",
  createdAt,
  updatedAt: null,
} as const satisfies Account;

export const baseAccountPayableDocument = {
  id: "ap-document-1",
  companyId: baseCompany.id,
  businessPartnerId: baseBusinessPartner.id,
  currencyId: baseCurrency.id,
  payableControlAccountId: payableAccount.id,
  documentType: "INVOICE",
  correctionOfId: null,
  documentNumber: "AP-10000001",
  externalDocumentNumber: "VEND-1001",
  documentDate: new Date("2024-01-10"),
  postingDate: new Date("2024-01-15"),
  totalAmount: "1000",
  description: "Vendor invoice",
  status: "DRAFT",
  registeredAt: null,
  postedAt: null,
  cancelledAt: null,
  createdAt,
  updatedAt: null,
} as const satisfies AccountPayableDocument<Schema>;

export const registeredAccountPayableDocument = {
  ...baseAccountPayableDocument,
  status: "REGISTERED",
  registeredAt: createdAt,
} as const satisfies AccountPayableDocument<Schema>;

export const postedAccountPayableDocument = {
  ...registeredAccountPayableDocument,
  status: "POSTED",
  postedAt: createdAt,
} as const satisfies AccountPayableDocument<Schema>;

export const creditMemoAccountPayableDocument = {
  ...registeredAccountPayableDocument,
  id: "ap-document-credit-1",
  documentType: "CREDIT_MEMO",
} as const satisfies AccountPayableDocument<Schema>;

export const baseAccountPayableDocumentLine = {
  id: "ap-document-line-1",
  accountPayableDocumentId: baseAccountPayableDocument.id,
  netAmount: "1000",
  taxAmount: null,
  grossAmount: "1000",
  correctionOfLineId: null,
  correctionType: null,
  quantity: "10",
  unitPrice: "100",
  unitId: "unit-1",
  description: "Purchase order line",
  sourceType: "PURCHASE_ORDER",
  purchaseOrderLineId: "purchase-order-line-1",
  createdAt,
  updatedAt: null,
} as const satisfies AccountPayableDocumentLine<Schema>;

export const baseAccountPayableDistributionLine = {
  id: "ap-distribution-line-1",
  accountPayableDocumentLineId: baseAccountPayableDocumentLine.id,
  correctionOfDistributionLineId: null,
  accountId: expenseAccount.id,
  amount: "1000",
  description: "Expense distribution",
  createdAt,
  updatedAt: null,
} as const satisfies AccountPayableDistributionLine<Schema>;

export const baseAccountPayableDueScheduleLine = {
  id: "ap-due-schedule-line-1",
  accountPayableDocumentId: baseAccountPayableDocument.id,
  dueDate: new Date("2024-02-15"),
  amount: "1000",
  createdAt,
  updatedAt: null,
} as const satisfies AccountPayableDueScheduleLine<Schema>;

export const basePurchaseOrderLineForMatching = {
  id: "purchase-order-line-1",
  purchaseOrderId: "purchase-order-1",
  quantity: "10",
  unitPrice: "100",
  unitId: "unit-1",
  requiresPhysicalReceipt: true,
} as const satisfies PurchaseOrderLineForMatching;

export const basePurchaseReceiptQuantityForMatching = {
  purchaseOrderLineId: "purchase-order-line-1",
  receivedQuantity: "10",
} as const satisfies PurchaseReceiptQuantityForMatching;
