/**
 * Email Types - Type definitions for the email system
 * All data structures are strictly typed with no hardcoded values
 */

export type LanguageCode = "en" | "sr" | "de" | "fr";
export type PaymentMethod = "card" | "cod" | "paypal" | "bank_transfer" | "unknown";
export type OrderStatus = "draft" | "unconfirmed" | "unfulfilled" | "partially_fulfilled" | "fulfilled" | "canceled";

export interface Money {
  amount: number;
  currency: string;
}

export interface Address {
  firstName?: string | null;
  lastName?: string | null;
  streetAddress1?: string | null;
  streetAddress2?: string | null;
  city?: string | null;
  postalCode?: string | null;
  country?: {
    country?: string | null;
    code?: string | null;
  } | null;
  phone?: string | null;
}

export interface OrderLine {
  quantity: number;
  variant?: {
    name?: string;
    product?: {
      name?: string;
    };
  };
  totalPrice?: {
    gross?: Money;
  };
}

export interface Transaction {
  id?: string;
  message?: string;
  externalUrl?: string;
  events?: TransactionEvent[];
}

export interface TransactionEvent {
  id?: string;
  message?: string;
  type?: string;
  amount?: Money;
}

export interface SaleorOrder {
  id: string;
  number?: string | null;
  created?: string | null;
  status?: string | null;
  languageCode?: string | null;
  userEmail?: string | null;
  shippingAddress?: Address | null;
  billingAddress?: Address | null;
  lines?: OrderLine[] | null;
  subtotal?: {
    gross?: Money | null;
  } | null;
  shippingPrice?: {
    gross?: Money | null;
  } | null;
  total?: {
    gross?: Money | null;
    tax?: Money | null;
  } | null;
  transactions?: Transaction[] | null;
  metadata?: Array<{
    key: string;
    value: string;
  }> | null;
}

export interface PaymentMethodConfig {
  id: PaymentMethod;
  label: string;
  icon?: string;
}

export interface EmailTemplateConfig {
  subject: string;
  title: string;
  greeting: string;
  body: string;
  orderLabel: string;
  dateLabel: string;
  statusLabel: string;
  itemsLabel: string;
  subtotalLabel: string;
  shippingLabel: string;
  taxLabel: string;
  totalLabel: string;
  shippingAddressLabel: string;
  phoneLabel: string;
  phoneNotProvided: string;
  viewOrderButton: string;
  thankYou: string;
  companyName: string;
  footerText: string;
}

export interface AdminEmailTemplateConfig {
  adminTitle: string;
  adminOrderLabel: string;
  customerLabel: string;
  nameLabel: string;
  emailLabel: string;
  dashboardButton: string;
}

export interface EmailData {
  orderNumber: string;
  customerName: string;
  greeting: string;
  subject: string;
  orderDate: string;
  orderStatus: string;
  items: Array<{
    name: string;
    quantity: number;
    price: string;
  }>;
  subtotal: string;
  shipping: string;
  tax: string;
  total: string;
  shippingAddress: string;
  phone: string;
  paymentMethod?: string;
  paymentLabel?: string;
  [key: string]: any;
}

export interface AdminEmailData extends EmailData {
  customerEmail: string;
  adminTitle: string;
  adminOrderLabel: string;
  customerLabel: string;
  nameLabel: string;
  emailLabel: string;
  dashboardButton: string;
}

export interface EmailResult {
  customerSubject: string;
  customerHtml: string;
  adminSubject: string;
  adminHtml: string;
}

export interface EmailServiceConfig {
  fromEmail: string;
  fromName: string;
  adminEmails: string[];
  companyName: string;
  companyLogoUrl: string;
  dashboardUrl: string;
  storefrontUrl: string;
  trackingUrl?: string;
}
