/**
 * The shapes of the oversight screens: the activity log, the sign-in history
 * and the recycle bin.
 *
 * These mirror App\Support\Presenters\AuditPresenter, the recycle bin's items
 * and the statistics each controller sends. Server and client are kept in step
 * by hand, so when a presenter changes, change the matching type here in the
 * same commit.
 */

export type AuditEventKey = "created" | "updated" | "deleted" | "restored";

export type AuditEntry = {
    id: number;
    event: {
        value: AuditEventKey;
        label: string;
        verb: string;
        tone: string;
    };
    module: string;
    tone: string;
    record: {
        kind: string;
        title: string;
        id: number;
        exists: boolean;
        hidden: boolean;
        url: string | null;
    };
    actor: {
        name: string;
        email: string | null;
        kind: "staff" | "customer" | "system";
        kind_label: string;
    };
    changes: Array<{
        field: string;
        label: string;
        old: string | null;
        new: string | null;
    }>;
    fields: string[];
    ip: string | null;
    device: string;
    at: string | null;
};

export type AuditModule = {
    value: string;
    label: string;
    tone: string;
};

export type AuditStats = {
    today: number;
    week: number;
    hidden_this_week: number;
    people_this_week: number;
    in_bin: number;
};

export type SignInKey = "login" | "failed" | "logout";

export type SignInEntry = {
    id: number;
    event: { value: SignInKey; label: string; tone: string };
    source: {
        value: "crm" | "portal" | "board" | "status_link";
        label: string;
        short: string;
        tone: string;
    };
    name: string;
    email: string | null;
    user_id: number | null;
    successful: boolean;
    reason: string | null;
    ip: string | null;
    device: string;
    device_short: string;
    at: string | null;
};

export type SignInSource = {
    value: string;
    label: string;
    tone: string;
    description: string;
};

export type SignInStats = {
    signed_in_today: number;
    failed_today: number;
    people_this_week: number;
    failed_this_week: number;
};

export type SignInAlert = {
    email: string;
    attempts: number;
    last_attempt: string | null;
};

export type RecycleCategory = {
    key: string;
    label: string;
    module: string;
    tone: string;
    count: number;
};

export type RecycleItem = {
    key: string;
    id: number;
    label: string;
    module: string;
    tone: string;
    title: string;
    subtitle: string | null;
    deleted_at: string | null;
    deleted_by: string;
    deleted_by_kind: "staff" | "customer" | "system";
    fields: Array<{ label: string; value: string }>;
    blocked_reason: string | null;
    can_restore: boolean;
};

export type RecycleStats = {
    total: number;
    modules: number;
    restorable: number;
};
