import type { fulfillmentMethodValues, orderStatusValues, paymentMethodValues, paymentStatusValues } from "../db/schema.js";

export type FulfillmentMethod = (typeof fulfillmentMethodValues)[number];
export type OrderStatus = (typeof orderStatusValues)[number];
export type PaymentMethod = (typeof paymentMethodValues)[number];
export type PaymentStatus = (typeof paymentStatusValues)[number];

export type PublicOrderItem = {
  id: number;
  productId: number | null;
  productName: string;
  sku: string;
  quantity: number;
  unitPrice: number;
  discountAmount: number;
  lineTotal: number;
  lensChoice: string;
  prescriptionUrl: string | null;
};

export type PublicOrder = {
  id: number;
  orderNumber: string;
  status: OrderStatus;
  fulfillmentMethod: FulfillmentMethod;
  contactPhone: string;
  deliveryAddress: string | null;
  subtotal: number;
  totalDiscount: number;
  totalAmount: number;
  paymentMethod: PaymentMethod;
  paymentStatus: PaymentStatus;
  customerNotes: string | null;
  createdAt: Date;
  updatedAt: Date;
  items: PublicOrderItem[];
};

export type AdminOrderListItem = Omit<PublicOrder, "items"> & {
  customer: {
    id: number;
    email: string;
    name: string | null;
    phoneNumber: string | null;
  };
  managedByStaff: {
    id: number;
    name: string;
    email: string;
  } | null;
  itemCount: number;
};

export type AdminOrderDetail = AdminOrderListItem & {
  items: PublicOrderItem[];
  staffNotes: string | null;
};

export type PaginationMeta = {
  page: number;
  perPage: number;
  total: number;
  totalPages: number;
  hasNextPage: boolean;
  hasPreviousPage: boolean;
};

export type PaginatedOrders<TOrder> = {
  items: TOrder[];
  pagination: PaginationMeta;
};
