import type { FiscalYear, AccountingPeriod, JournalEntry, JournalLine, Schema } from "../lib/types";
import type { Company } from "./moduleMocks";

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

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

export const baseAccount = {
  id: "account-1",
  code: "1000",
  name: "Cash",
  classification: "ASSET",
  status: "ACTIVE",
  successorAccountId: null,
};

export const baseAccount2 = {
  id: "account-2",
  code: "2000",
  name: "Accounts Payable",
  classification: "LIABILITY",
  status: "ACTIVE",
  successorAccountId: null,
};

export const receivableAccount = {
  id: "account-receivable",
  code: "1100",
  name: "Accounts Receivable",
  classification: "RECEIVABLE",
  status: "ACTIVE",
  successorAccountId: null,
};

export const payableAccount = {
  id: "account-payable",
  code: "2100",
  name: "Accounts Payable Control",
  classification: "PAYABLE",
  status: "ACTIVE",
  successorAccountId: null,
};

export const inactiveAccount = {
  ...baseAccount,
  id: "account-inactive",
  status: "INACTIVE",
  successorAccountId: null,
};

export const deprecatedAccount = {
  ...baseAccount,
  id: "account-deprecated",
  status: "DEPRECATED",
  successorAccountId: baseAccount.id,
};

export const retainedEarningsAccount = {
  id: "account-retained-earnings",
  code: "3100",
  name: "Retained Earnings",
  classification: "RETAINED_EARNINGS",
  status: "ACTIVE",
  successorAccountId: null,
};

export const revenueAccount = {
  id: "account-revenue",
  code: "4000",
  name: "Sales Revenue",
  classification: "REVENUE",
  status: "ACTIVE",
  successorAccountId: null,
};

export const expenseAccount = {
  id: "account-expense",
  code: "5000",
  name: "Cost of Goods Sold",
  classification: "EXPENSE",
  status: "ACTIVE",
  successorAccountId: null,
};

export const baseAccountGroup = {
  id: "account-group-1",
  name: "Current Assets",
  code: "CA",
};

export const baseChartOfAccounts = {
  id: "coa-1",
  companyId: baseCompany.id,
  status: "ACTIVE",
};

export const baseUser = {
  id: "user-1",
  status: "ACTIVE",
};

export const baseFiscalYear = {
  id: "fiscal-year-1",
  companyId: baseCompany.id,
  name: "FY 2024",
  startDate: new Date("2024-01-01"),
  endDate: new Date("2024-12-31"),
  yearEndCloseExecuted: false,
  createdAt,
  updatedAt: null,
} as const satisfies FiscalYear<Schema>;

export const baseFiscalYear2 = {
  ...baseFiscalYear,
  id: "fiscal-year-2",
  name: "FY 2025",
  startDate: new Date("2025-01-01"),
  endDate: new Date("2025-12-31"),
} as const satisfies FiscalYear<Schema>;

export const baseAccountingPeriod = {
  id: "period-1",
  companyId: baseCompany.id,
  fiscalYearId: baseFiscalYear.id,
  name: "January 2024",
  startDate: new Date("2024-01-01"),
  endDate: new Date("2024-01-31"),
  periodType: "OPERATING",
  status: "OPEN",
  createdAt,
  updatedAt: null,
} as const satisfies AccountingPeriod<Schema>;

export const neverOpenedPeriod = {
  ...baseAccountingPeriod,
  id: "period-never-opened",
  status: "NEVER_OPENED",
} as const satisfies AccountingPeriod<Schema>;

export const closedPeriod = {
  ...baseAccountingPeriod,
  id: "period-closed",
  status: "CLOSED",
} as const satisfies AccountingPeriod<Schema>;

export const permanentlyClosedPeriod = {
  ...baseAccountingPeriod,
  id: "period-permanently-closed",
  status: "PERMANENTLY_CLOSED",
} as const satisfies AccountingPeriod<Schema>;

export const lastPeriodOfYear = {
  ...baseAccountingPeriod,
  id: "period-last",
  name: "December 2024",
  startDate: new Date("2024-12-01"),
  endDate: new Date("2024-12-31"),
} as const satisfies AccountingPeriod<Schema>;

export const baseJournalEntry = {
  id: "journal-entry-1",
  companyId: baseCompany.id,
  accountingPeriodId: baseAccountingPeriod.id,
  entryDate: new Date("2024-01-15"),
  status: "DRAFT",
  description: "Test journal entry",
  sourceDocumentType: null,
  sourceDocumentId: null,
  reversalOfId: null,
  postedAt: null,
  createdAt,
  updatedAt: null,
} as const satisfies JournalEntry<Schema>;

export const postedJournalEntry = {
  ...baseJournalEntry,
  id: "journal-entry-2",
  status: "POSTED",
  postedAt: createdAt,
} as const satisfies JournalEntry<Schema>;

export const cancelledJournalEntry = {
  ...baseJournalEntry,
  id: "journal-entry-cancelled",
  status: "CANCELLED",
} as const satisfies JournalEntry<Schema>;

export const baseJournalLine = {
  id: "journal-line-1",
  journalEntryId: baseJournalEntry.id,
  accountId: baseAccount.id,
  debitAmount: "1000",
  creditAmount: null,
  description: "Debit line",
  createdAt,
  updatedAt: null,
} as const satisfies JournalLine<Schema>;

export const baseJournalLine2 = {
  id: "journal-line-2",
  journalEntryId: baseJournalEntry.id,
  accountId: baseAccount2.id,
  debitAmount: null,
  creditAmount: "1000",
  description: "Credit line",
  createdAt,
  updatedAt: null,
} as const satisfies JournalLine<Schema>;
