const std = @import("std");

const protocol = @import("eink_feed_protocol");

const models = @import("../../../models/root.zig");

// pub const PixelFormat = enum {
//     grayscale,

//     pub fn fromInternal(value: protocol.models.PixelFormat) PixelFormat {
//         return switch (value) {
//             .grayscale => .grayscale,
//         };
//     }
// };

pub const Orientation = enum {
    portrait_up,
    portrait_down,
    landscape_left,
    landscape_right,

    pub fn fromString(str: []const u8) ?Orientation {
        if (std.mem.eql(u8, str, "portrait_up")) {
            return .portrait_up;
        } else if (std.mem.eql(u8, str, "portrait_down")) {
            return .portrait_down;
        } else if (std.mem.eql(u8, str, "landscape_left")) {
            return .landscape_left;
        } else if (std.mem.eql(u8, str, "landscape_right")) {
            return .landscape_right;
        } else {
            return null;
        }
    }

    pub fn toString(self: Orientation) []const u8 {
        return switch (self) {
            .portrait_up => "portrait_up",
            .portrait_down => "portrait_down",
            .landscape_left => "landscape_left",
            .landscape_right => "landscape_right",
        };
    }

    pub fn fromInternal(value: protocol.models.Orientation) Orientation {
        return switch (value) {
            .portrait_up => .portrait_up,
            .portrait_down => .portrait_down,
            .landscape_left => .landscape_left,
            .landscape_right => .landscape_right,
        };
    }

    pub fn toInternal(value: Orientation) protocol.models.Orientation {
        return switch (value) {
            .portrait_up => .portrait_up,
            .portrait_down => .portrait_down,
            .landscape_left => .landscape_left,
            .landscape_right => .landscape_right,
        };
    }
};

pub const Display = struct {
    width: u32,
    height: u32,
    orientation: Orientation,

    pub fn fromInternal(value: protocol.models.Display) Display {
        return .{
            .width = value.width,
            .height = value.height,
            .orientation = Orientation.fromInternal(value.orientation),
        };
    }
};

pub const ChannelFrame = struct {
    timestamp: u64,
};

pub const Channel = struct {
    pub const Id = u32;

    id: Id,
    name: []const u8,
    display: Display,

    pub fn fromInternal(value: *const models.Channel) Channel {
        return Channel{
            .id = value.id,
            .name = value.nameSlice(),
            .display = Display.fromInternal(value.display),
        };
    }
};
