use serde::{Deserialize, Serialize};

use crate::event::conditions::RuntimeCondition;
use crate::event::effects::RuntimeEffect;

#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct RuntimeEventRecordTemplate {
    pub record_id: u32,
    pub trigger_kind: u8,
    pub active: bool,
    #[serde(default)]
    pub marks_collection_dirty: bool,
    #[serde(default)]
    pub one_shot: bool,
    #[serde(default)]
    pub conditions: Vec<RuntimeCondition>,
    #[serde(default)]
    pub effects: Vec<RuntimeEffect>,
}

#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct RuntimeEventRecord {
    pub record_id: u32,
    pub trigger_kind: u8,
    pub active: bool,
    #[serde(default)]
    pub service_count: u32,
    #[serde(default)]
    pub marks_collection_dirty: bool,
    #[serde(default)]
    pub one_shot: bool,
    #[serde(default)]
    pub has_fired: bool,
    #[serde(default)]
    pub conditions: Vec<RuntimeCondition>,
    #[serde(default)]
    pub effects: Vec<RuntimeEffect>,
}

impl RuntimeEventRecordTemplate {
    pub fn into_runtime_record(self) -> RuntimeEventRecord {
        RuntimeEventRecord {
            record_id: self.record_id,
            trigger_kind: self.trigger_kind,
            active: self.active,
            service_count: 0,
            marks_collection_dirty: self.marks_collection_dirty,
            one_shot: self.one_shot,
            has_fired: false,
            conditions: self.conditions,
            effects: self.effects,
        }
    }
}
