package storage

import (
	"context"
	"fmt"
	"github.com/jackc/pgx/v5"
	"madsky.ru/go-tracker/internal/database"
)

type UserToProjectRepository interface {
	Create(ctx context.Context, userId uint32, projectId uint32) error
}

type UserToProjectStore struct {
	client database.Client
}

func (up *UserToProjectStore) Create(ctx context.Context, userId uint32, projectId uint32) error {
	query := `insert into user_to_project (user_id, project_id) values (@userId, @projectId)`

	args := pgx.NamedArgs{
		"userId":    userId,
		"projectId": projectId,
	}

	_, err := up.client.Exec(ctx, query, args)
	if err != nil {
		return fmt.Errorf("unable to insert row: %w", err)
	}

	return nil
}
