use crate::templating::{TemplateIter, TemplateTone, Templater};

pub struct EngineeringBlog;

impl EngineeringBlog {
    pub fn as_templater() -> Box<dyn Templater> {
        Box::new(EngineeringBlog)
    }
}

impl Templater for EngineeringBlog {
    fn title(&self) -> &'static str {
        "On Reducing Redundant Execution in Concurrent Services"
    }

    fn tone(&self) -> TemplateTone {
        TemplateTone::Casual
    }

    fn introduction(&self) -> TemplateIter {
        fhtml::concat! {
            <h1>"On Reducing Redundant Execution in Concurrent Services"</h1>
            <div style="font-size: 12px; color: #666">"systems note"</div>

            <p>
                "The most persistent inefficiencies in production systems are rarely
                algorithmic in nature. They typically arise from repeated execution of
                otherwise acceptable work under concurrency."
            </p>

            <p>
                "In a recent investigation, a service exhibited elevated resource usage
                without any obvious hotspots in profiling data. Individual requests were
                inexpensive; aggregate behavior was not."
            </p>

            <blockquote>
                "Observation: the system was performing equivalent work multiple times
                per unit of demand."
            </blockquote>

            <h2>"change"</h2>
        }
        .into()
    }

    fn follow_up(&self) -> TemplateIter {
        fhtml::concat! {
            <p>
                "The adjustment introduces coordination at the boundary of execution.
                Rather than optimizing the operation itself, it ensures identical work
                is not repeated concurrently."
            </p>

            <p>
                "This distinction matters. Optimization reduces cost per operation.
                Coordination reduces the number of operations."
            </p>

            <hr>

            <h2>"result"</h2>

            <p>
                "After deployment, observed improvements were consistent across load
                profiles: reduced CPU consumption, lower tail latency, and improved
                stability under burst conditions."
            </p>

            <p>
                "The more significant effect was not peak performance, but reduced
                variance. Systems became easier to reason about under stress."
            </p>

            <hr>

            <h2>"closing remark"</h2>

            <p>
                "This class of issue tends to recur in distributed systems. It is not
                usually visible in isolated traces, and it often survives basic
                optimization efforts."
            </p>

            <p>
                "The solution, when it appears, is typically structural rather than
                computational."
            </p>

            <h2>"references"</h2>
        }
        .into()
    }

    fn tail(&self) -> TemplateIter {
        fhtml::concat! {
            <footer>"engineering archive — internal systems notes"</footer>
        }
        .into()
    }
}
