import type {
  ApprovalDecision,
  ApprovalPolicy,
  ApprovalPolicyStep,
  ApprovalPolicyStepAssignee,
  ApprovalRequest,
  ApprovalStep,
  ApprovalStepAssignee,
  Schema,
} from "../lib/types";

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

// ApprovalPolicy ────────────────────────────────────────────────────────────

export const draftPolicy = {
  id: "policy-draft-1",
  purpose: "PRODUCT_ACTIVATION",
  name: "Standard Product",
  description: "Standard 2-step product activation chain",
  status: "DRAFT",
  activatedAt: null,
  deactivatedAt: null,
  createdAt: baseTimestamp,
  updatedAt: null,
} as const satisfies ApprovalPolicy<Schema>;

export const activePolicy = {
  id: "policy-active-1",
  purpose: "PRODUCT_ACTIVATION",
  name: "Standard Product",
  description: "Standard 2-step product activation chain",
  status: "ACTIVE",
  activatedAt: new Date("2024-02-01T00:00:00.000Z"),
  deactivatedAt: null,
  createdAt: baseTimestamp,
  updatedAt: new Date("2024-02-01T00:00:00.000Z"),
} as const satisfies ApprovalPolicy<Schema>;

export const inactivePolicy = {
  id: "policy-inactive-1",
  purpose: "PRODUCT_ACTIVATION",
  name: "Standard Product",
  description: "Superseded variant",
  status: "INACTIVE",
  activatedAt: new Date("2024-01-15T00:00:00.000Z"),
  deactivatedAt: new Date("2024-02-01T00:00:00.000Z"),
  createdAt: baseTimestamp,
  updatedAt: new Date("2024-02-01T00:00:00.000Z"),
} as const satisfies ApprovalPolicy<Schema>;

// ApprovalPolicyStep / Assignee ─────────────────────────────────────────────

export const policyStep1 = {
  id: "policy-step-1",
  approvalPolicyId: "policy-active-1",
  stepOrder: 1,
  name: "Manager review",
  minimumApprovals: 1,
  createdAt: baseTimestamp,
  updatedAt: null,
} as const satisfies ApprovalPolicyStep<Schema>;

export const policyStep2 = {
  id: "policy-step-2",
  approvalPolicyId: "policy-active-1",
  stepOrder: 2,
  name: "Director review",
  minimumApprovals: 1,
  createdAt: baseTimestamp,
  updatedAt: null,
} as const satisfies ApprovalPolicyStep<Schema>;

export const policyAssigneeUser = {
  id: "policy-assignee-user-1",
  approvalPolicyStepId: "policy-step-1",
  userId: "user-manager-1",
  roleId: null,
  required: false,
  roleQuorum: null,
  createdAt: baseTimestamp,
  updatedAt: null,
} as const satisfies ApprovalPolicyStepAssignee<Schema>;

export const policyAssigneeRole = {
  id: "policy-assignee-role-1",
  approvalPolicyStepId: "policy-step-2",
  userId: null,
  roleId: "role-director",
  required: false,
  roleQuorum: null,
  createdAt: baseTimestamp,
  updatedAt: null,
} as const satisfies ApprovalPolicyStepAssignee<Schema>;

// ApprovalRequest ───────────────────────────────────────────────────────────

export const pendingRequest = {
  id: "request-pending-1",
  name: "Activate Product P-200",
  purpose: "PRODUCT_ACTIVATION",
  targetEntityType: "Product",
  targetEntityId: "product-200",
  requesterId: "user-requester-1",
  sourcePolicyId: "policy-active-1",
  status: "PENDING",
  rejectionReason: null,
  resolvedAt: null,
  createdAt: baseTimestamp,
  updatedAt: null,
} as const satisfies ApprovalRequest<Schema>;

export const approvedRequest = {
  id: "request-approved-1",
  name: "Activate Product P-300",
  purpose: "PRODUCT_ACTIVATION",
  targetEntityType: "Product",
  targetEntityId: "product-300",
  requesterId: "user-requester-1",
  sourcePolicyId: "policy-active-1",
  status: "APPROVED",
  rejectionReason: null,
  resolvedAt: new Date("2024-03-05T00:00:00.000Z"),
  createdAt: baseTimestamp,
  updatedAt: new Date("2024-03-05T00:00:00.000Z"),
} as const satisfies ApprovalRequest<Schema>;

export const rejectedRequest = {
  id: "request-rejected-1",
  name: "Activate Product P-400",
  purpose: "PRODUCT_ACTIVATION",
  targetEntityType: "Product",
  targetEntityId: "product-400",
  requesterId: "user-requester-1",
  sourcePolicyId: "policy-active-1",
  status: "REJECTED",
  rejectionReason: "Exceeds Q2 budget cap",
  resolvedAt: new Date("2024-03-04T00:00:00.000Z"),
  createdAt: baseTimestamp,
  updatedAt: new Date("2024-03-04T00:00:00.000Z"),
} as const satisfies ApprovalRequest<Schema>;

export const withdrawnRequest = {
  id: "request-withdrawn-1",
  name: "Activate Product P-500",
  purpose: "PRODUCT_ACTIVATION",
  targetEntityType: "Product",
  targetEntityId: "product-500",
  requesterId: "user-requester-1",
  sourcePolicyId: "policy-active-1",
  status: "WITHDRAWN",
  rejectionReason: null,
  resolvedAt: new Date("2024-03-02T00:00:00.000Z"),
  createdAt: baseTimestamp,
  updatedAt: new Date("2024-03-02T00:00:00.000Z"),
} as const satisfies ApprovalRequest<Schema>;

export const cancelledRequest = {
  id: "request-cancelled-1",
  name: "Activate Product P-600",
  purpose: "PRODUCT_ACTIVATION",
  targetEntityType: "Product",
  targetEntityId: "product-600",
  requesterId: "user-requester-1",
  sourcePolicyId: "policy-active-1",
  status: "CANCELLED",
  rejectionReason: null,
  resolvedAt: new Date("2024-03-03T00:00:00.000Z"),
  createdAt: baseTimestamp,
  updatedAt: new Date("2024-03-03T00:00:00.000Z"),
} as const satisfies ApprovalRequest<Schema>;

export const revisionRequestedRequest = {
  id: "request-revision-1",
  name: "Activate Product P-700",
  purpose: "PRODUCT_ACTIVATION",
  targetEntityType: "Product",
  targetEntityId: "product-700",
  requesterId: "user-requester-1",
  sourcePolicyId: "policy-active-1",
  status: "REVISION_REQUESTED",
  rejectionReason: null,
  resolvedAt: null,
  createdAt: baseTimestamp,
  updatedAt: new Date("2024-03-06T00:00:00.000Z"),
} as const satisfies ApprovalRequest<Schema>;

// ApprovalStep ──────────────────────────────────────────────────────────────

export const pendingStep1 = {
  id: "step-pending-1",
  approvalRequestId: "request-pending-1",
  stepOrder: 1,
  name: "Manager review",
  minimumApprovals: 1,
  status: "PENDING",
  resolvedAt: null,
  createdAt: baseTimestamp,
  updatedAt: null,
} as const satisfies ApprovalStep<Schema>;

export const inProgressStep1 = {
  id: "step-in-progress-1",
  approvalRequestId: "request-pending-1",
  stepOrder: 1,
  name: "Manager review",
  minimumApprovals: 1,
  status: "IN_PROGRESS",
  resolvedAt: null,
  createdAt: baseTimestamp,
  updatedAt: new Date("2024-03-01T00:00:00.000Z"),
} as const satisfies ApprovalStep<Schema>;

export const pendingStep2 = {
  id: "step-pending-2",
  approvalRequestId: "request-pending-1",
  stepOrder: 2,
  name: "Director review",
  minimumApprovals: 1,
  status: "PENDING",
  resolvedAt: null,
  createdAt: baseTimestamp,
  updatedAt: null,
} as const satisfies ApprovalStep<Schema>;

// ApprovalStepAssignee ──────────────────────────────────────────────────────

export const pendingAssigneeUser = {
  id: "assignee-pending-user-1",
  approvalStepId: "step-in-progress-1",
  userId: "user-manager-1",
  roleId: null,
  required: false,
  roleQuorum: null,
  status: "PENDING",
  resolvedAt: null,
  createdAt: baseTimestamp,
  updatedAt: null,
} as const satisfies ApprovalStepAssignee<Schema>;

export const pendingAssigneeRoleRow = {
  id: "assignee-pending-role-1",
  approvalStepId: "step-pending-2",
  userId: null,
  roleId: "role-director",
  required: false,
  roleQuorum: null,
  status: "PENDING",
  resolvedAt: null,
  createdAt: baseTimestamp,
  updatedAt: null,
} as const satisfies ApprovalStepAssignee<Schema>;

// ApprovalDecision ──────────────────────────────────────────────────────────

export const approveDecision = {
  id: "decision-approve-1",
  approvalRequestId: "request-pending-1",
  approvalStepId: "step-in-progress-1",
  decision: "APPROVE",
  decidedByUserId: "user-manager-1",
  delegatedToUserId: null,
  comment: null,
  decidedAt: new Date("2024-03-02T00:00:00.000Z"),
  createdAt: new Date("2024-03-02T00:00:00.000Z"),
  updatedAt: null,
} as const satisfies ApprovalDecision<Schema>;
