package models

import (
	"context"
	"database/sql"
	. "screenmark/screenmark/.gen/haystack/haystack/table"

	"github.com/google/uuid"
)

type TextModel struct {
	dbPool *sql.DB
}

func (m TextModel) Save(ctx context.Context, imageId uuid.UUID, texts []string) error {
	if len(texts) == 0 {
		return nil
	}

	saveImageTextStmt := ImageText.INSERT(ImageText.ImageID, ImageText.ImageText)

	for _, t := range texts {
		saveImageTextStmt = saveImageTextStmt.VALUES(imageId, t)
	}

	saveImageTextStmt.RETURNING(ImageText.AllColumns)

	_, err := saveImageTextStmt.ExecContext(ctx, m.dbPool)

	return err
}

func NewTextModel(db *sql.DB) TextModel {
	return TextModel{dbPool: db}
}
