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

use fixer::tag::Tag;
use fixer::fix_string::FIXString;
use fixer::fix_boolean::FIXBoolean;
use fixer::fix_int::FIXInt;
use fixer::fix_float::FIXFloat;
use fixer::fix_decimal::FIXDecimal;
use fixer::fix_utc_timestamp::FIXUTCTimestamp;
use fixer::field::{FieldValueReader, FieldValueWriter, FieldValue};
use simple_error::SimpleResult;
use crate::tag;
{% if needs_decimal %}
use rust_decimal::Decimal;
{% endif %}
{% if needs_timestamp %}
use fixer::fix_utc_timestamp::TimestampPrecision;
use jiff::Timestamp;
{% endif %}

{% for field in fields %}
/// `{{ field.name }}Field` is a `{{ field.fix_type }}` field, Tag {{ field.tag }}.
pub struct {{ field.name }}Field(pub {{ field.fixer_type }});

impl {{ field.name }}Field {
{% if field.fixer_type == "FIXString" %}
    pub fn new(val: String) -> Self { Self(val) }
    pub fn value(&self) -> &str { &self.0 }
{% elif field.fixer_type == "FIXBoolean" %}
    pub fn new(val: bool) -> Self { Self(val) }
    pub fn value(&self) -> bool { self.0 }
{% elif field.fixer_type == "FIXInt" %}
    pub fn new(val: isize) -> Self { Self(val) }
    pub fn value(&self) -> isize { self.0 }
{% elif field.fixer_type == "FIXFloat" %}
    pub fn new(val: f64) -> Self { Self(val) }
    pub fn value(&self) -> f64 { self.0 }
{% elif field.fixer_type == "FIXDecimal" %}
    pub fn new(val: Decimal, scale: i32) -> Self {
        Self(FIXDecimal { decimal: val, scale })
    }
    pub fn value(&self) -> Decimal { self.0.decimal }
{% elif field.fixer_type == "FIXUTCTimestamp" %}
    pub fn new(val: Timestamp) -> Self {
        Self(FIXUTCTimestamp { time: val, precision: TimestampPrecision::Millis })
    }
    pub fn value(&self) -> Timestamp { self.0.time }
{% endif %}
    pub fn tag() -> Tag { tag::{{ field.const_name }} }
}

impl FieldValueReader for {{ field.name }}Field {
    fn read(&mut self, raw: &[u8]) -> SimpleResult<()> {
        self.0.read(raw)
    }
}

impl FieldValueWriter for {{ field.name }}Field {
    fn write_to(&self, buf: &mut Vec<u8>) {
        self.0.write_to(buf);
    }
}

impl FieldValue for {{ field.name }}Field {}

{% endfor %}
