import type {
  AuditableEntity,
  AuditPolicy,
  PolicyFieldRule,
  AuditEntry,
  ChangeDetail,
  Schema,
} from "../lib/types";

// AuditableEntity fixtures
export const companyBoundEntity = {
  id: "entity-1",
  entityName: "SalesOrder",
  entityScope: "COMPANY_BOUND",
  auditableFields: JSON.stringify([
    { fieldName: "amount", fieldType: "scalar" },
    { fieldName: "status", fieldType: "scalar" },
    { fieldName: "customerId", fieldType: "relation" },
  ]),
  createdAt: new Date("2024-01-01T00:00:00.000Z"),
  updatedAt: null,
} as const satisfies AuditableEntity<Schema>;

export const globalEntity = {
  id: "entity-2",
  entityName: "User",
  entityScope: "GLOBAL",
  auditableFields: JSON.stringify([
    { fieldName: "email", fieldType: "scalar" },
    { fieldName: "role", fieldType: "scalar" },
    { fieldName: "isActive", fieldType: "scalar" },
  ]),
  createdAt: new Date("2024-01-01T00:00:00.000Z"),
  updatedAt: null,
} as const satisfies AuditableEntity<Schema>;

// AuditPolicy fixtures
export const draftPolicy = {
  id: "policy-1",
  entityName: "SalesOrder",
  companyId: "company-1",
  operationType: "UPDATE",
  status: "DRAFT",
  createdAt: new Date("2024-01-01T00:00:00.000Z"),
  updatedAt: null,
} as const satisfies AuditPolicy<Schema>;

export const activePolicy = {
  id: "policy-2",
  entityName: "SalesOrder",
  companyId: "company-1",
  operationType: "UPDATE",
  status: "ACTIVE",
  createdAt: new Date("2024-01-01T00:00:00.000Z"),
  updatedAt: null,
} as const satisfies AuditPolicy<Schema>;

export const inactivePolicy = {
  id: "policy-3",
  entityName: "SalesOrder",
  companyId: "company-1",
  operationType: "UPDATE",
  status: "INACTIVE",
  createdAt: new Date("2024-01-01T00:00:00.000Z"),
  updatedAt: null,
} as const satisfies AuditPolicy<Schema>;

export const globalDraftPolicy = {
  id: "policy-4",
  entityName: "User",
  companyId: null,
  operationType: "CREATE",
  status: "DRAFT",
  createdAt: new Date("2024-01-01T00:00:00.000Z"),
  updatedAt: null,
} as const satisfies AuditPolicy<Schema>;

export const globalActivePolicy = {
  id: "policy-5",
  entityName: "User",
  companyId: null,
  operationType: "CREATE",
  status: "ACTIVE",
  createdAt: new Date("2024-01-01T00:00:00.000Z"),
  updatedAt: null,
} as const satisfies AuditPolicy<Schema>;

export const draftReplacementPolicy = {
  id: "policy-6",
  entityName: "SalesOrder",
  companyId: "company-1",
  operationType: "UPDATE",
  status: "DRAFT",
  createdAt: new Date("2024-01-01T00:00:00.000Z"),
  updatedAt: null,
} as const satisfies AuditPolicy<Schema>;

// PolicyFieldRule fixtures
export const captureFieldRule = {
  id: "rule-1",
  auditPolicyId: "policy-2",
  fieldName: "amount",
  sensitivityMode: "CAPTURE",
  createdAt: new Date("2024-01-01T00:00:00.000Z"),
  updatedAt: null,
} as const satisfies PolicyFieldRule<Schema>;

export const maskFieldRule = {
  id: "rule-2",
  auditPolicyId: "policy-2",
  fieldName: "customerId",
  sensitivityMode: "MASK",
  createdAt: new Date("2024-01-01T00:00:00.000Z"),
  updatedAt: null,
} as const satisfies PolicyFieldRule<Schema>;

export const hashFieldRule = {
  id: "rule-3",
  auditPolicyId: "policy-2",
  fieldName: "status",
  sensitivityMode: "HASH",
  createdAt: new Date("2024-01-01T00:00:00.000Z"),
  updatedAt: null,
} as const satisfies PolicyFieldRule<Schema>;

export const excludeFieldRule = {
  id: "rule-4",
  auditPolicyId: "policy-2",
  fieldName: "amount",
  sensitivityMode: "EXCLUDE",
  createdAt: new Date("2024-01-01T00:00:00.000Z"),
  updatedAt: null,
} as const satisfies PolicyFieldRule<Schema>;

// AuditEntry fixtures
export const baseAuditEntry = {
  id: "entry-1",
  eventId: "event-uuid-1",
  actorType: "USER",
  actorId: "user-1",
  entityType: "SalesOrder",
  entityId: "so-1",
  operationType: "UPDATE",
  companyId: "company-1",
  correlationId: null,
  ipAddress: null,
  userAgent: null,
  sessionId: null,
  requestId: null,
  onBehalfOf: null,
  timestamp: new Date("2024-01-15T10:30:00.000Z"),
  createdAt: new Date("2024-01-15T10:30:00.000Z"),
  updatedAt: null,
} as const satisfies AuditEntry<Schema>;

export const globalAuditEntry = {
  id: "entry-2",
  eventId: "event-uuid-2",
  actorType: "SYSTEM",
  actorId: "system-job-1",
  entityType: "User",
  entityId: "user-2",
  operationType: "CREATE",
  companyId: null,
  correlationId: "corr-uuid-1",
  ipAddress: "192.168.1.1",
  userAgent: "AuditBot/1.0",
  sessionId: "session-1",
  requestId: "req-1",
  onBehalfOf: "user-3",
  timestamp: new Date("2024-01-16T12:00:00.000Z"),
  createdAt: new Date("2024-01-16T12:00:00.000Z"),
  updatedAt: null,
} as const satisfies AuditEntry<Schema>;

// ChangeDetail fixtures
export const baseChangeDetail = {
  id: "detail-1",
  auditEntryId: "entry-1",
  fieldName: "amount",
  oldValue: "100.00",
  newValue: "95.00",
  createdAt: new Date("2024-01-15T10:30:00.000Z"),
  updatedAt: null,
} as const satisfies ChangeDetail<Schema>;

export const maskedChangeDetail = {
  id: "detail-2",
  auditEntryId: "entry-1",
  fieldName: "customerId",
  oldValue: "***",
  newValue: "***",
  createdAt: new Date("2024-01-15T10:30:00.000Z"),
  updatedAt: null,
} as const satisfies ChangeDetail<Schema>;

export const excludedChangeDetail = {
  id: "detail-3",
  auditEntryId: "entry-1",
  fieldName: "amount",
  oldValue: null,
  newValue: null,
  createdAt: new Date("2024-01-15T10:30:00.000Z"),
  updatedAt: null,
} as const satisfies ChangeDetail<Schema>;

export const createChangeDetail = {
  id: "detail-4",
  auditEntryId: "entry-2",
  fieldName: "email",
  oldValue: null,
  newValue: "user@example.com",
  createdAt: new Date("2024-01-16T12:00:00.000Z"),
  updatedAt: null,
} as const satisfies ChangeDetail<Schema>;
