// Derived from PDFium's constants/annotation_flags.h
// Original: Copyright 2019 The PDFium Authors
// Licensed under BSD-3-Clause / Apache-2.0
// See pdfium-upstream/LICENSE for the original license.

//! Annotation flag bit values.
//!
//! Corresponds to `pdfium::annotation_flags` namespace.
//! PDF 1.7 spec, table 8.16.

/// Annotation is invisible (do not display if unknown subtype).
pub const K_INVISIBLE: u32 = 1 << 0;

/// Annotation is hidden.
pub const K_HIDDEN: u32 = 1 << 1;

/// Annotation should be printed.
pub const K_PRINT: u32 = 1 << 2;

/// Do not zoom annotation when the page is zoomed.
pub const K_NO_ZOOM: u32 = 1 << 3;

/// Do not rotate annotation when the page is rotated.
pub const K_NO_ROTATE: u32 = 1 << 4;

/// Do not display annotation on screen.
pub const K_NO_VIEW: u32 = 1 << 5;

/// Annotation is read-only.
pub const K_READ_ONLY: u32 = 1 << 6;

/// Annotation is locked.
pub const K_LOCKED: u32 = 1 << 7;

/// Toggle the no-view state.
pub const K_TOGGLE_NO_VIEW: u32 = 1 << 8;

/// Annotation contents are locked.
pub const K_LOCKED_CONTENTS: u32 = 1 << 9;

// ---------------------------------------------------------------------------
// Tests — verify bit positions match PDF 1.7 spec Table 8.16
// ---------------------------------------------------------------------------

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn test_bit_positions_match_pdf_spec() {
        // PDF 1.7 Table 8.16: bit numbering is 1-based in the spec; our
        // constants use 0-based bit shifts.
        assert_eq!(K_INVISIBLE, 0x001); // bit 1
        assert_eq!(K_HIDDEN, 0x002); // bit 2
        assert_eq!(K_PRINT, 0x004); // bit 3
        assert_eq!(K_NO_ZOOM, 0x008); // bit 4
        assert_eq!(K_NO_ROTATE, 0x010); // bit 5
        assert_eq!(K_NO_VIEW, 0x020); // bit 6
        assert_eq!(K_READ_ONLY, 0x040); // bit 7
        assert_eq!(K_LOCKED, 0x080); // bit 8
        assert_eq!(K_TOGGLE_NO_VIEW, 0x100); // bit 9
        assert_eq!(K_LOCKED_CONTENTS, 0x200); // bit 10
    }

    #[test]
    fn test_flags_are_disjoint() {
        let all = [
            K_INVISIBLE,
            K_HIDDEN,
            K_PRINT,
            K_NO_ZOOM,
            K_NO_ROTATE,
            K_NO_VIEW,
            K_READ_ONLY,
            K_LOCKED,
            K_TOGGLE_NO_VIEW,
            K_LOCKED_CONTENTS,
        ];
        for (i, &a) in all.iter().enumerate() {
            for (j, &b) in all.iter().enumerate() {
                if i != j {
                    assert_eq!(a & b, 0, "flags at indices {i} and {j} overlap");
                }
            }
        }
    }

    #[test]
    fn test_flags_can_be_combined_with_or() {
        let combined = K_PRINT | K_READ_ONLY;
        assert_ne!(combined & K_PRINT, 0);
        assert_ne!(combined & K_READ_ONLY, 0);
        assert_eq!(combined & K_HIDDEN, 0);
    }
}
