package public

import (
	"context"

	"github.com/Gleipnir-Technology/jet/postgres"
	"source.gleipnir.technology/Gleipnir/nidus-sync/db"
	"source.gleipnir.technology/Gleipnir/nidus-sync/db/gen/nidus-sync/public/model"
	"source.gleipnir.technology/Gleipnir/nidus-sync/db/gen/nidus-sync/public/table"
)

func JobInsert(ctx context.Context, txn db.Ex, m model.Job) (model.Job, error) {
	statement := table.Job.INSERT(table.Job.MutableColumns).
		MODEL(m).
		RETURNING(table.Job.AllColumns)
	return db.ExecuteOneTx[model.Job](ctx, txn, statement)
}
func JobNotify(ctx context.Context, txn db.Ex, channel string, payload string) error {
	statement := postgres.RawStatement(
		"SELECT pg_notify(#channel, #payload)",
		postgres.RawArgs{
			"#channel": channel,
			"#payload": payload,
		},
	)
	return db.ExecuteNoneTx(ctx, txn, statement)
}
