const std = @import("std");

const protobuf = @import("root.zig").protobuf;

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

//     pub fn fromProtobuf(value: protobuf.PixelFormat) PixelFormat {
//         return switch (value) {
//             .GRAYSCALE => .grayscale,
//             _ => .grayscale,
//         };
//     }

//     pub fn toProtobuf(self: PixelFormat) protobuf.PixelFormat {
//         return switch (self) {
//             .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 fromProtobuf(value: protobuf.Orientation) Orientation {
        return switch (value) {
            .PORTRAIT_UP => .portrait_up,
            .PORTRAIT_DOWN => .portrait_down,
            .LANDSCAPE_LEFT => .landscape_left,
            .LANDSCAPE_RIGHT => .landscape_right,
            _ => .portrait_up,
        };
    }

    pub fn toProtobuf(self: Orientation) protobuf.Orientation {
        return switch (self) {
            .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 fromProtobuf(value: protobuf.Display) Display {
        return .{
            // .format = PixelFormat.fromProtobuf(value.format),
            .width = value.width,
            .height = value.height,
            .orientation = Orientation.fromProtobuf(value.orientation),
        };
    }

    pub fn toProtobuf(self: Display, allocator: std.mem.Allocator) protobuf.Display {
        var display = protobuf.Display.init(allocator);
        // display.format = self.format.toProtobuf();
        display.width = self.width;
        display.height = self.height;
        display.orientation = self.orientation.toProtobuf();

        return display;
    }
};

// pub const FrameConfig = struct {
//     fps: ?u32 = null,
//     display: Display,

//     pub fn fromProtobuf(value: protobuf.FrameConfig) FrameConfig {
//         return .{
//             .fps = value.fps,
//             .display = Display.fromProtobuf(value.display.?),
//         };
//     }

//     pub fn toProtobuf(self: FrameConfig, allocator: std.mem.Allocator) protobuf.FrameConfig {
//         var frame_config = protobuf.FrameConfig.init(allocator);
//         frame_config.fps = self.fps;
//         frame_config.display = self.display.toProtobuf(allocator);

//         return frame_config;
//     }
// };

pub const Frame = struct {
    display: Display,
    pixels: []const u8,
};
