package models

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

	"github.com/google/uuid"
)

type LinkModel struct {
	dbPool *sql.DB
}

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

	stmt := ImageLinks.INSERT(ImageLinks.ImageID, ImageLinks.Link)

	for _, link := range links {
		stmt = stmt.VALUES(imageId, link)
	}

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

	return err
}

func NewLinkModel(db *sql.DB) LinkModel {
	return LinkModel{dbPool: db}
}
