use binrw::{BinRead, BinWrite};
use diff::Diff;

use crate::{
    array_of::ArrayOf,
    objects::Object,
    types::{Field, WString, F64, U16, U32},
};

#[derive(BinRead, BinWrite, Debug, Diff, PartialEq)]
#[diff(attr(
    #[derive(Debug, PartialEq)]
))]
#[brw(magic(17u32))] // Number of fields within this struct
pub struct LayerSettings1 {
    _unknown_1: [Field; 3],
    pub name: WString,
    pub count: U32,
    _unknown_2: Field,
    pub input_signal_wait_enable_mask: U16,
    pub input_signal_wait_disable_mask: U16,
    _unknown_3: [Field; 9],
}

#[derive(BinRead, BinWrite, Debug, Diff, PartialEq)]
#[diff(attr(
    #[derive(Debug, PartialEq)]
))]
#[brw(magic(152u32))] // Number of fields within this struct
pub struct LayerSettings2 {
    _unknown_4: [Field; 54],
    pub output_signal_start_enable_mask: U16,
    pub output_signal_start_disable_mask: U16,
    pub output_signal_end_enable_mask: U16,
    pub output_signal_end_disable_mask: U16,
    _unknown_5: [Field; 9],
    pub fixture_offset: F64,
    _unknown_6: [Field; 64],
    pub output_signal_start_delay: U32,
    pub output_signal_end_delay: U32,
    pub input_signal_wait_enable: U32,
    _unknown_7: [Field; 2],
    pub output_signal_start_pulse: U32,
    pub output_signal_end_pulse: U32,
    _unknown_8: [Field; 13],
    footer: u32,
}

#[derive(BinRead, BinWrite, Debug, Diff, PartialEq)]
#[diff(attr(
    #[derive(Debug, PartialEq)]
))]
pub struct Layer {
    pub pre: LayerSettings1,
    pub objects: ArrayOf<Object>,
    pub post: LayerSettings2,
}
