// Code generated by fixer-gen. DO NOT EDIT.
#![allow(clippy::new_without_default)]
#![allow(unused_imports)]

use fixer::field_map::FieldMap;
use fixer::fix_string::FIXString;
use crate::tag;

/// `Header` is the `{{ package }}` Header type.
pub struct Header<'a> {
    pub header: &'a mut FieldMap,
}

impl Header<'_> {
    /// Creates a new `Header` wrapping the given message header.
    pub fn new(header: &mut FieldMap) -> Header<'_> {
        header.set_field(tag::BEGIN_STRING, FIXString::from("{{ begin_string }}".to_string()));
        Header { header }
    }

{% for f in fields %}
{% if f.is_group %}
    // TODO: group setter/getter for {{ f.name }}
{% else %}
{% if f.fixer_type == "FIXString" %}
    /// Sets `{{ f.name }}`, Tag {{ f.tag }}.
    pub fn set_{{ f.snake_name }}(&mut self, v: String) {
        self.header.set_field(tag::{{ f.const_name }}, FIXString::from(v));
    }
{% elif f.fixer_type == "FIXInt" %}
    /// Sets `{{ f.name }}`, Tag {{ f.tag }}.
    pub fn set_{{ f.snake_name }}(&mut self, v: isize) {
        self.header.set_field(tag::{{ f.const_name }}, fixer::fix_int::FIXInt::from(v));
    }
{% elif f.fixer_type == "FIXBoolean" %}
    /// Sets `{{ f.name }}`, Tag {{ f.tag }}.
    pub fn set_{{ f.snake_name }}(&mut self, v: bool) {
        self.header.set_field(tag::{{ f.const_name }}, fixer::fix_boolean::FIXBoolean::from(v));
    }
{% elif f.fixer_type == "FIXUTCTimestamp" %}
    /// Sets `{{ f.name }}`, Tag {{ f.tag }}.
    pub fn set_{{ f.snake_name }}(&mut self, v: jiff::Timestamp) {
        self.header.set_field(tag::{{ f.const_name }}, fixer::fix_utc_timestamp::FIXUTCTimestamp {
            time: v,
            precision: fixer::fix_utc_timestamp::TimestampPrecision::Millis,
        });
    }
{% endif %}

    /// Returns true if `{{ f.name }}` is present, Tag {{ f.tag }}.
    pub fn has_{{ f.snake_name }}(&self) -> bool {
        self.header.has(tag::{{ f.const_name }})
    }
{% endif %}
{% endfor %}
}
