package display

import (
	rgbmatrix "git.dvdt.dev/david/bitcoin-ticker-pi/go-rpi-rgb-led-matrix"
)

type Display struct {
	canvas *rgbmatrix.Canvas

	tl, tr, c, bl, br *Slot
}

func New(canvas *rgbmatrix.Canvas, tl, tr, c, bl, br *Slot) *Display {
	return &display{
		canvas: canvas,
		tl:     tl,
		tr:     tr,
		c:      c,
		bl:     bl,
		br:     br,
	}
}

func (d *Display) UpdateTopLeft(text []Segment) error {
	err := d.tl.Update(text)
	if err != nil {
		return err
	}
	d.tl.Draw(d.canvas)
	return nil
}

func (d *Display) UpdateTopRight(text []Segment) error {
	err := d.tr.Update(text)
	if err != nil {
		return err
	}
	d.tr.Draw(d.canvas)
	return nil
}

func (d *Display) UpdateCenter(text []Segment) error {
	err := d.c.Update(text)
	if err != nil {
		return err
	}
	d.c.Draw(d.canvas)
	return nil
}

func (d *Display) UpdateBottomLeft(text []Segment) error {
	err := d.bl.Update(text)
	if err != nil {
		return err
	}
	d.bl.Draw(d.canvas)
	return nil
}

func (d *Display) UpdateBottomRight(text []Segment) error {
	err := d.br.Update(text)
	if err != nil {
		return err
	}
	d.bl.Draw(d.canvas)
	return nil
}

func (d *Display) Render() error {
	return d.canvas.Render()
}
