const Date = @import("../Date.zig");

/// A stock split event.
pub const Split = struct {
    date: Date,
    /// Number of shares after the split (e.g., 4 in a 4:1 split)
    numerator: f64,
    /// Number of shares before the split (e.g., 1 in a 4:1 split)
    denominator: f64,

    /// Returns the split ratio (e.g., 4.0 for a 4:1 split)
    pub fn ratio(self: Split) f64 {
        return self.numerator / self.denominator;
    }
};

const std = @import("std");

test "split ratio" {
    const forward = Split{ .date = Date{ .days = 19000 }, .numerator = 4, .denominator = 1 };
    try std.testing.expectApproxEqAbs(@as(f64, 4.0), forward.ratio(), 0.001);
    const reverse = Split{ .date = Date{ .days = 19000 }, .numerator = 1, .denominator = 10 };
    try std.testing.expectApproxEqAbs(@as(f64, 0.1), reverse.ratio(), 0.001);
    const two_for_one = Split{ .date = Date{ .days = 19000 }, .numerator = 2, .denominator = 1 };
    try std.testing.expectApproxEqAbs(@as(f64, 2.0), two_for_one.ratio(), 0.001);
}
