export type Role = 'admin' | 'owner' | 'staff';
export type BillingStatus = 'free' | 'trial' | 'active' | 'overdue' | 'expired' | 'suspended';

export interface AuthUser {
    id: number;
    name: string;
    role: Role;
    roleLabel: string;
}

export interface BusinessInfo {
    name: string;
    type: string;
    /** its own look: colour, and logo (or initials when it has none) */
    brandColor: string;
    logoUrl: string | null;
    initials: string;
    currency: string;
    canChangePrice: boolean;
    /** customers, credit and loan reminders are switched on */
    loansEnabled: boolean;
    /** kaunjika: bales instead of a product list */
    balesEnabled: boolean;
    /** shifts are in use (the header shows the shift) */
    usesShifts: boolean;
    /** prepaid SMS left (owner only, when loans are on) */
    smsLeft: number | null;
    /** only sent to the owner */
    billing: { status: BillingStatus; label: string; trialEnds: string | null; trialDaysLeft: number | null; locksOn: string | null; fee: string } | null;
}

export interface SharedProps {
    /** the app's name (APP_NAME) */
    appName: string;
    auth: AuthUser | null;
    business: BusinessInfo | null;
    /** the time your shift opened, when it is open */
    shift: string | null;
    locale: 'en' | 'ny';
    flash: { status?: string | null; sale?: { number: number; total: string; method: string; late?: boolean } | null };
    errors: Record<string, string>;
    [key: string]: unknown;
}

export interface Paginated<T> {
    data: T[];
    total: number;
    from: number | null;
    to: number | null;
    prev: string | null;
    next: string | null;
    currentPage: number;
    lastPage: number;
}

export interface Product {
    id: number;
    name: string;
    kind: 'product' | 'service' | 'supply';
    unit: string | null;
    /** how it is sold: each (by the piece) or loose by kg, litre or metre */
    sellUnit: 'each' | 'kg' | 'litre' | 'metre';
    /** how its quantities read: kg, L, m, or a piece's name (packet) */
    unitLabel: string | null;
    categoryId: number | null;
    category: string | null;
    price: number;
    priceLabel: string;
    priceInput: string;
    trackStock: boolean;
    stock: number | null;
    lowStockAt: number | null;
    isLow: boolean;
    isActive: boolean;
    /** owner only */
    costPrice?: number | null;
    costInput?: string;
    costLabel?: string | null;
    margin?: number | null;
}

export interface Sale {
    id: number;
    number: number;
    kind: 'items' | 'quick';
    total: number;
    totalLabel: string;
    method: string;
    methodLabel: string;
    note: string | null;
    soldAt: string;
    time: string;
    by: string | null;
    customer: { id: number; name: string } | null;
    enteredLate: boolean;
    itemCount: number | null;
    summary: string | null;
    voided: boolean;
    voidedAt: string | null;
    voidedBy: string | null;
    voidReason: string | null;
    profitLabel?: string;
    items?: { name: string; quantity: number; quantityLabel: string; unitPriceLabel: string; lineTotalLabel: string }[];
}

export interface Person {
    id: number;
    name: string;
    phone: string;
    phoneLabel: string;
    role: Role;
    roleLabel: string;
    isActive: boolean;
    lastLogin: string | null;
}
