// Code generated by sqlc. DO NOT EDIT.
// versions:
//   sqlc v1.29.0
// source: sync.sql

package sqlcv1

import (
	"context"

	"github.com/google/uuid"
	"github.com/jackc/pgx/v5/pgtype"
)

const syncSoftDeleteTenant = `-- name: SyncSoftDeleteTenant :exec
UPDATE "Tenant"
SET
    "deletedAt" = $1::timestamp,
    "slug" = $2::text
WHERE "id" = $3::uuid
`

type SyncSoftDeleteTenantParams struct {
	Deletedat pgtype.Timestamp `json:"deletedat"`
	Slug      string           `json:"slug"`
	ID        uuid.UUID        `json:"id"`
}

func (q *Queries) SyncSoftDeleteTenant(ctx context.Context, db DBTX, arg SyncSoftDeleteTenantParams) error {
	_, err := db.Exec(ctx, syncSoftDeleteTenant, arg.Deletedat, arg.Slug, arg.ID)
	return err
}

const syncUpdateTenant = `-- name: SyncUpdateTenant :one
UPDATE "Tenant"
SET
    "updatedAt" = $1::timestamp,
    "name" = COALESCE($2::text, "name"),
    "analyticsOptOut" = COALESCE($3::boolean, "analyticsOptOut"),
    "alertMemberEmails" = COALESCE($4::boolean, "alertMemberEmails"),
    "version" = COALESCE($5::"TenantMajorEngineVersion", "version")
WHERE "id" = $6::uuid
RETURNING id, "createdAt", "updatedAt", "deletedAt", version, "uiVersion", name, slug, "analyticsOptOut", "alertMemberEmails", "controllerPartitionId", "workerPartitionId", "dataRetentionPeriod", "schedulerPartitionId", "canUpgradeV1", "onboardingData", environment
`

type SyncUpdateTenantParams struct {
	Updatedat         pgtype.Timestamp             `json:"updatedat"`
	Name              pgtype.Text                  `json:"name"`
	AnalyticsOptOut   pgtype.Bool                  `json:"analyticsOptOut"`
	AlertMemberEmails pgtype.Bool                  `json:"alertMemberEmails"`
	Version           NullTenantMajorEngineVersion `json:"version"`
	ID                uuid.UUID                    `json:"id"`
}

func (q *Queries) SyncUpdateTenant(ctx context.Context, db DBTX, arg SyncUpdateTenantParams) (*Tenant, error) {
	row := db.QueryRow(ctx, syncUpdateTenant,
		arg.Updatedat,
		arg.Name,
		arg.AnalyticsOptOut,
		arg.AlertMemberEmails,
		arg.Version,
		arg.ID,
	)
	var i Tenant
	err := row.Scan(
		&i.ID,
		&i.CreatedAt,
		&i.UpdatedAt,
		&i.DeletedAt,
		&i.Version,
		&i.UiVersion,
		&i.Name,
		&i.Slug,
		&i.AnalyticsOptOut,
		&i.AlertMemberEmails,
		&i.ControllerPartitionId,
		&i.WorkerPartitionId,
		&i.DataRetentionPeriod,
		&i.SchedulerPartitionId,
		&i.CanUpgradeV1,
		&i.OnboardingData,
		&i.Environment,
	)
	return &i, err
}

const syncUpdateTenantInvite = `-- name: SyncUpdateTenantInvite :one
UPDATE "TenantInviteLink"
SET
    "updatedAt" = $1::timestamp,
    "status" = COALESCE($2::"InviteLinkStatus", "status"),
    "role" = COALESCE($3::"TenantMemberRole", "role")
WHERE "id" = $4::uuid
RETURNING id, "createdAt", "updatedAt", "tenantId", "inviterEmail", "inviteeEmail", expires, status, role
`

type SyncUpdateTenantInviteParams struct {
	Updatedat pgtype.Timestamp     `json:"updatedat"`
	Status    NullInviteLinkStatus `json:"status"`
	Role      NullTenantMemberRole `json:"role"`
	ID        uuid.UUID            `json:"id"`
}

func (q *Queries) SyncUpdateTenantInvite(ctx context.Context, db DBTX, arg SyncUpdateTenantInviteParams) (*TenantInviteLink, error) {
	row := db.QueryRow(ctx, syncUpdateTenantInvite,
		arg.Updatedat,
		arg.Status,
		arg.Role,
		arg.ID,
	)
	var i TenantInviteLink
	err := row.Scan(
		&i.ID,
		&i.CreatedAt,
		&i.UpdatedAt,
		&i.TenantId,
		&i.InviterEmail,
		&i.InviteeEmail,
		&i.Expires,
		&i.Status,
		&i.Role,
	)
	return &i, err
}

const syncUpdateTenantMember = `-- name: SyncUpdateTenantMember :one
UPDATE "TenantMember"
SET
    "updatedAt" = $1::timestamp,
    "role" = $2::"TenantMemberRole"
WHERE "id" = $3::uuid
RETURNING id, "createdAt", "updatedAt", "tenantId", "userId", role
`

type SyncUpdateTenantMemberParams struct {
	Updatedat pgtype.Timestamp `json:"updatedat"`
	Role      TenantMemberRole `json:"role"`
	ID        uuid.UUID        `json:"id"`
}

func (q *Queries) SyncUpdateTenantMember(ctx context.Context, db DBTX, arg SyncUpdateTenantMemberParams) (*TenantMember, error) {
	row := db.QueryRow(ctx, syncUpdateTenantMember, arg.Updatedat, arg.Role, arg.ID)
	var i TenantMember
	err := row.Scan(
		&i.ID,
		&i.CreatedAt,
		&i.UpdatedAt,
		&i.TenantId,
		&i.UserId,
		&i.Role,
	)
	return &i, err
}

const syncUpsertTenant = `-- name: SyncUpsertTenant :one
INSERT INTO "Tenant" (
    "id",
    "createdAt",
    "updatedAt",
    "name",
    "slug",
    "dataRetentionPeriod",
    "version",
    "uiVersion",
    "onboardingData",
    "environment",
    "analyticsOptOut",
    "alertMemberEmails",
    "canUpgradeV1"
) VALUES (
    $1::uuid,
    $2::timestamp,
    $3::timestamp,
    $4::text,
    $5::text,
    $6::text,
    $7::"TenantMajorEngineVersion",
    $8::"TenantMajorUIVersion",
    $9::jsonb,
    $10::"TenantEnvironment",
    $11::boolean,
    $12::boolean,
    $13::boolean
) ON CONFLICT ("id") DO UPDATE SET
    "updatedAt" = $3::timestamp,
    "name" = $4::text,
    "slug" = $5::text,
    "dataRetentionPeriod" = $6::text,
    "version" = $7::"TenantMajorEngineVersion",
    "uiVersion" = $8::"TenantMajorUIVersion",
    "onboardingData" = $9::jsonb,
    "environment" = $10::"TenantEnvironment",
    "analyticsOptOut" = $11::boolean,
    "alertMemberEmails" = $12::boolean,
    "canUpgradeV1" = $13::boolean
RETURNING id, "createdAt", "updatedAt", "deletedAt", version, "uiVersion", name, slug, "analyticsOptOut", "alertMemberEmails", "controllerPartitionId", "workerPartitionId", "dataRetentionPeriod", "schedulerPartitionId", "canUpgradeV1", "onboardingData", environment
`

type SyncUpsertTenantParams struct {
	ID                  uuid.UUID                `json:"id"`
	Createdat           pgtype.Timestamp         `json:"createdat"`
	Updatedat           pgtype.Timestamp         `json:"updatedat"`
	Name                string                   `json:"name"`
	Slug                string                   `json:"slug"`
	Dataretentionperiod string                   `json:"dataretentionperiod"`
	Version             TenantMajorEngineVersion `json:"version"`
	Uiversion           TenantMajorUIVersion     `json:"uiversion"`
	OnboardingData      []byte                   `json:"onboardingData"`
	Environment         NullTenantEnvironment    `json:"environment"`
	Analyticsoptout     bool                     `json:"analyticsoptout"`
	Alertmemberemails   bool                     `json:"alertmemberemails"`
	Canupgradev1        bool                     `json:"canupgradev1"`
}

func (q *Queries) SyncUpsertTenant(ctx context.Context, db DBTX, arg SyncUpsertTenantParams) (*Tenant, error) {
	row := db.QueryRow(ctx, syncUpsertTenant,
		arg.ID,
		arg.Createdat,
		arg.Updatedat,
		arg.Name,
		arg.Slug,
		arg.Dataretentionperiod,
		arg.Version,
		arg.Uiversion,
		arg.OnboardingData,
		arg.Environment,
		arg.Analyticsoptout,
		arg.Alertmemberemails,
		arg.Canupgradev1,
	)
	var i Tenant
	err := row.Scan(
		&i.ID,
		&i.CreatedAt,
		&i.UpdatedAt,
		&i.DeletedAt,
		&i.Version,
		&i.UiVersion,
		&i.Name,
		&i.Slug,
		&i.AnalyticsOptOut,
		&i.AlertMemberEmails,
		&i.ControllerPartitionId,
		&i.WorkerPartitionId,
		&i.DataRetentionPeriod,
		&i.SchedulerPartitionId,
		&i.CanUpgradeV1,
		&i.OnboardingData,
		&i.Environment,
	)
	return &i, err
}

const syncUpsertTenantAlertingSettings = `-- name: SyncUpsertTenantAlertingSettings :one
INSERT INTO "TenantAlertingSettings" ("id", "tenantId")
VALUES ($1::uuid, $2::uuid)
ON CONFLICT ("id") DO UPDATE
SET "tenantId" = EXCLUDED."tenantId"
RETURNING id, "createdAt", "updatedAt", "deletedAt", "tenantId", "maxFrequency", "lastAlertedAt", "tickerId", "enableExpiringTokenAlerts", "enableWorkflowRunFailureAlerts", "enableTenantResourceLimitAlerts"
`

type SyncUpsertTenantAlertingSettingsParams struct {
	ID       uuid.UUID `json:"id"`
	Tenantid uuid.UUID `json:"tenantid"`
}

// dummy update to avoid "ON CONFLICT DO NOTHING" which doesn't return the row
func (q *Queries) SyncUpsertTenantAlertingSettings(ctx context.Context, db DBTX, arg SyncUpsertTenantAlertingSettingsParams) (*TenantAlertingSettings, error) {
	row := db.QueryRow(ctx, syncUpsertTenantAlertingSettings, arg.ID, arg.Tenantid)
	var i TenantAlertingSettings
	err := row.Scan(
		&i.ID,
		&i.CreatedAt,
		&i.UpdatedAt,
		&i.DeletedAt,
		&i.TenantId,
		&i.MaxFrequency,
		&i.LastAlertedAt,
		&i.TickerId,
		&i.EnableExpiringTokenAlerts,
		&i.EnableWorkflowRunFailureAlerts,
		&i.EnableTenantResourceLimitAlerts,
	)
	return &i, err
}

const syncUpsertTenantInvite = `-- name: SyncUpsertTenantInvite :one
INSERT INTO "TenantInviteLink" (
    "id",
    "createdAt",
    "updatedAt",
    "tenantId",
    "inviterEmail",
    "inviteeEmail",
    "expires",
    "role",
    "status"
) VALUES (
    $1::uuid,
    $2::timestamp,
    $3::timestamp,
    $4::uuid,
    $5::text,
    $6::text,
    $7::timestamp,
    $8::"TenantMemberRole",
    $9::"InviteLinkStatus"
) ON CONFLICT ("id") DO UPDATE SET
    "updatedAt" = $3::timestamp,
    "inviterEmail" = $5::text,
    "inviteeEmail" = $6::text,
    "expires" = $7::timestamp,
    "role" = $8::"TenantMemberRole",
    "status" = $9::"InviteLinkStatus"
RETURNING id, "createdAt", "updatedAt", "tenantId", "inviterEmail", "inviteeEmail", expires, status, role
`

type SyncUpsertTenantInviteParams struct {
	ID           uuid.UUID        `json:"id"`
	Createdat    pgtype.Timestamp `json:"createdat"`
	Updatedat    pgtype.Timestamp `json:"updatedat"`
	Tenantid     uuid.UUID        `json:"tenantid"`
	Inviteremail string           `json:"inviteremail"`
	Inviteeemail string           `json:"inviteeemail"`
	Expires      pgtype.Timestamp `json:"expires"`
	Role         TenantMemberRole `json:"role"`
	Status       InviteLinkStatus `json:"status"`
}

func (q *Queries) SyncUpsertTenantInvite(ctx context.Context, db DBTX, arg SyncUpsertTenantInviteParams) (*TenantInviteLink, error) {
	row := db.QueryRow(ctx, syncUpsertTenantInvite,
		arg.ID,
		arg.Createdat,
		arg.Updatedat,
		arg.Tenantid,
		arg.Inviteremail,
		arg.Inviteeemail,
		arg.Expires,
		arg.Role,
		arg.Status,
	)
	var i TenantInviteLink
	err := row.Scan(
		&i.ID,
		&i.CreatedAt,
		&i.UpdatedAt,
		&i.TenantId,
		&i.InviterEmail,
		&i.InviteeEmail,
		&i.Expires,
		&i.Status,
		&i.Role,
	)
	return &i, err
}

const syncUpsertTenantMember = `-- name: SyncUpsertTenantMember :one
INSERT INTO "TenantMember" (
    "id",
    "createdAt",
    "updatedAt",
    "tenantId",
    "userId",
    "role"
) VALUES (
    $1::uuid,
    $2::timestamp,
    $3::timestamp,
    $4::uuid,
    $5::uuid,
    $6::"TenantMemberRole"
) ON CONFLICT ("id") DO UPDATE SET
    "updatedAt" = $3::timestamp,
    "role" = $6::"TenantMemberRole"
RETURNING id, "createdAt", "updatedAt", "tenantId", "userId", role
`

type SyncUpsertTenantMemberParams struct {
	ID        uuid.UUID        `json:"id"`
	Createdat pgtype.Timestamp `json:"createdat"`
	Updatedat pgtype.Timestamp `json:"updatedat"`
	Tenantid  uuid.UUID        `json:"tenantid"`
	Userid    uuid.UUID        `json:"userid"`
	Role      TenantMemberRole `json:"role"`
}

func (q *Queries) SyncUpsertTenantMember(ctx context.Context, db DBTX, arg SyncUpsertTenantMemberParams) (*TenantMember, error) {
	row := db.QueryRow(ctx, syncUpsertTenantMember,
		arg.ID,
		arg.Createdat,
		arg.Updatedat,
		arg.Tenantid,
		arg.Userid,
		arg.Role,
	)
	var i TenantMember
	err := row.Scan(
		&i.ID,
		&i.CreatedAt,
		&i.UpdatedAt,
		&i.TenantId,
		&i.UserId,
		&i.Role,
	)
	return &i, err
}

const syncUpsertUser = `-- name: SyncUpsertUser :one
INSERT INTO "User" (
    "id",
    "createdAt",
    "updatedAt",
    "email",
    "emailVerified",
    "name"
) VALUES (
    $1::uuid,
    $2::timestamp,
    $3::timestamp,
    $4::text,
    $5::boolean,
    $6::text
) ON CONFLICT ("id") DO UPDATE SET
    "updatedAt" = $3::timestamp,
    "email" = $4::text,
    "emailVerified" = $5::boolean,
    "name" = $6::text
RETURNING id, "createdAt", "updatedAt", "deletedAt", email, "emailVerified", name
`

type SyncUpsertUserParams struct {
	ID            uuid.UUID        `json:"id"`
	Createdat     pgtype.Timestamp `json:"createdat"`
	Updatedat     pgtype.Timestamp `json:"updatedat"`
	Email         string           `json:"email"`
	Emailverified bool             `json:"emailverified"`
	Name          pgtype.Text      `json:"name"`
}

func (q *Queries) SyncUpsertUser(ctx context.Context, db DBTX, arg SyncUpsertUserParams) (*User, error) {
	row := db.QueryRow(ctx, syncUpsertUser,
		arg.ID,
		arg.Createdat,
		arg.Updatedat,
		arg.Email,
		arg.Emailverified,
		arg.Name,
	)
	var i User
	err := row.Scan(
		&i.ID,
		&i.CreatedAt,
		&i.UpdatedAt,
		&i.DeletedAt,
		&i.Email,
		&i.EmailVerified,
		&i.Name,
	)
	return &i, err
}
