// Code generated by sqlc. DO NOT EDIT.
// versions:
//   sqlc v1.30.0
// source: alias.sql

package repository

import (
	"context"
)

const deleteArtistAlias = `-- name: DeleteArtistAlias :exec
DELETE FROM artist_aliases 
WHERE artist_id = $1
AND alias = $2
AND is_primary = false
`

type DeleteArtistAliasParams struct {
	ArtistID int32
	Alias    string
}

func (q *Queries) DeleteArtistAlias(ctx context.Context, arg DeleteArtistAliasParams) error {
	_, err := q.db.Exec(ctx, deleteArtistAlias, arg.ArtistID, arg.Alias)
	return err
}

const deleteReleaseAlias = `-- name: DeleteReleaseAlias :exec
DELETE FROM release_aliases 
WHERE release_id = $1
AND alias = $2
AND is_primary = false
`

type DeleteReleaseAliasParams struct {
	ReleaseID int32
	Alias     string
}

func (q *Queries) DeleteReleaseAlias(ctx context.Context, arg DeleteReleaseAliasParams) error {
	_, err := q.db.Exec(ctx, deleteReleaseAlias, arg.ReleaseID, arg.Alias)
	return err
}

const deleteTrackAlias = `-- name: DeleteTrackAlias :exec
DELETE FROM track_aliases 
WHERE track_id = $1
AND alias = $2
AND is_primary = false
`

type DeleteTrackAliasParams struct {
	TrackID int32
	Alias   string
}

func (q *Queries) DeleteTrackAlias(ctx context.Context, arg DeleteTrackAliasParams) error {
	_, err := q.db.Exec(ctx, deleteTrackAlias, arg.TrackID, arg.Alias)
	return err
}

const getAllArtistAliases = `-- name: GetAllArtistAliases :many
SELECT artist_id, alias, source, is_primary FROM artist_aliases
WHERE artist_id = $1 ORDER BY is_primary DESC
`

func (q *Queries) GetAllArtistAliases(ctx context.Context, artistID int32) ([]ArtistAlias, error) {
	rows, err := q.db.Query(ctx, getAllArtistAliases, artistID)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	var items []ArtistAlias
	for rows.Next() {
		var i ArtistAlias
		if err := rows.Scan(
			&i.ArtistID,
			&i.Alias,
			&i.Source,
			&i.IsPrimary,
		); err != nil {
			return nil, err
		}
		items = append(items, i)
	}
	if err := rows.Err(); err != nil {
		return nil, err
	}
	return items, nil
}

const getAllReleaseAliases = `-- name: GetAllReleaseAliases :many
SELECT release_id, alias, source, is_primary FROM release_aliases
WHERE release_id = $1 ORDER BY is_primary DESC
`

func (q *Queries) GetAllReleaseAliases(ctx context.Context, releaseID int32) ([]ReleaseAlias, error) {
	rows, err := q.db.Query(ctx, getAllReleaseAliases, releaseID)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	var items []ReleaseAlias
	for rows.Next() {
		var i ReleaseAlias
		if err := rows.Scan(
			&i.ReleaseID,
			&i.Alias,
			&i.Source,
			&i.IsPrimary,
		); err != nil {
			return nil, err
		}
		items = append(items, i)
	}
	if err := rows.Err(); err != nil {
		return nil, err
	}
	return items, nil
}

const getAllTrackAliases = `-- name: GetAllTrackAliases :many
SELECT track_id, alias, is_primary, source FROM track_aliases
WHERE track_id = $1 ORDER BY is_primary DESC
`

func (q *Queries) GetAllTrackAliases(ctx context.Context, trackID int32) ([]TrackAlias, error) {
	rows, err := q.db.Query(ctx, getAllTrackAliases, trackID)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	var items []TrackAlias
	for rows.Next() {
		var i TrackAlias
		if err := rows.Scan(
			&i.TrackID,
			&i.Alias,
			&i.IsPrimary,
			&i.Source,
		); err != nil {
			return nil, err
		}
		items = append(items, i)
	}
	if err := rows.Err(); err != nil {
		return nil, err
	}
	return items, nil
}

const getArtistAlias = `-- name: GetArtistAlias :one
SELECT artist_id, alias, source, is_primary FROM artist_aliases
WHERE alias = $1 LIMIT 1
`

func (q *Queries) GetArtistAlias(ctx context.Context, alias string) (ArtistAlias, error) {
	row := q.db.QueryRow(ctx, getArtistAlias, alias)
	var i ArtistAlias
	err := row.Scan(
		&i.ArtistID,
		&i.Alias,
		&i.Source,
		&i.IsPrimary,
	)
	return i, err
}

const getReleaseAlias = `-- name: GetReleaseAlias :one
SELECT release_id, alias, source, is_primary FROM release_aliases
WHERE alias = $1 LIMIT 1
`

func (q *Queries) GetReleaseAlias(ctx context.Context, alias string) (ReleaseAlias, error) {
	row := q.db.QueryRow(ctx, getReleaseAlias, alias)
	var i ReleaseAlias
	err := row.Scan(
		&i.ReleaseID,
		&i.Alias,
		&i.Source,
		&i.IsPrimary,
	)
	return i, err
}

const getTrackAlias = `-- name: GetTrackAlias :one
SELECT track_id, alias, is_primary, source FROM track_aliases
WHERE alias = $1 LIMIT 1
`

func (q *Queries) GetTrackAlias(ctx context.Context, alias string) (TrackAlias, error) {
	row := q.db.QueryRow(ctx, getTrackAlias, alias)
	var i TrackAlias
	err := row.Scan(
		&i.TrackID,
		&i.Alias,
		&i.IsPrimary,
		&i.Source,
	)
	return i, err
}

const insertArtistAlias = `-- name: InsertArtistAlias :exec
INSERT INTO artist_aliases (artist_id, alias, source, is_primary)
VALUES ($1, $2, $3, $4)
ON CONFLICT DO NOTHING
`

type InsertArtistAliasParams struct {
	ArtistID  int32
	Alias     string
	Source    string
	IsPrimary bool
}

func (q *Queries) InsertArtistAlias(ctx context.Context, arg InsertArtistAliasParams) error {
	_, err := q.db.Exec(ctx, insertArtistAlias,
		arg.ArtistID,
		arg.Alias,
		arg.Source,
		arg.IsPrimary,
	)
	return err
}

const insertReleaseAlias = `-- name: InsertReleaseAlias :exec
INSERT INTO release_aliases (release_id, alias, source, is_primary)
VALUES ($1, $2, $3, $4)
ON CONFLICT DO NOTHING
`

type InsertReleaseAliasParams struct {
	ReleaseID int32
	Alias     string
	Source    string
	IsPrimary bool
}

func (q *Queries) InsertReleaseAlias(ctx context.Context, arg InsertReleaseAliasParams) error {
	_, err := q.db.Exec(ctx, insertReleaseAlias,
		arg.ReleaseID,
		arg.Alias,
		arg.Source,
		arg.IsPrimary,
	)
	return err
}

const insertTrackAlias = `-- name: InsertTrackAlias :exec
INSERT INTO track_aliases (track_id, alias, source, is_primary)
VALUES ($1, $2, $3, $4)
ON CONFLICT DO NOTHING
`

type InsertTrackAliasParams struct {
	TrackID   int32
	Alias     string
	Source    string
	IsPrimary bool
}

func (q *Queries) InsertTrackAlias(ctx context.Context, arg InsertTrackAliasParams) error {
	_, err := q.db.Exec(ctx, insertTrackAlias,
		arg.TrackID,
		arg.Alias,
		arg.Source,
		arg.IsPrimary,
	)
	return err
}

const setArtistAliasPrimaryStatus = `-- name: SetArtistAliasPrimaryStatus :exec
UPDATE artist_aliases SET is_primary = $1 WHERE artist_id = $2 AND alias = $3
`

type SetArtistAliasPrimaryStatusParams struct {
	IsPrimary bool
	ArtistID  int32
	Alias     string
}

func (q *Queries) SetArtistAliasPrimaryStatus(ctx context.Context, arg SetArtistAliasPrimaryStatusParams) error {
	_, err := q.db.Exec(ctx, setArtistAliasPrimaryStatus, arg.IsPrimary, arg.ArtistID, arg.Alias)
	return err
}

const setReleaseAliasPrimaryStatus = `-- name: SetReleaseAliasPrimaryStatus :exec
UPDATE release_aliases SET is_primary = $1 WHERE release_id = $2 AND alias = $3
`

type SetReleaseAliasPrimaryStatusParams struct {
	IsPrimary bool
	ReleaseID int32
	Alias     string
}

func (q *Queries) SetReleaseAliasPrimaryStatus(ctx context.Context, arg SetReleaseAliasPrimaryStatusParams) error {
	_, err := q.db.Exec(ctx, setReleaseAliasPrimaryStatus, arg.IsPrimary, arg.ReleaseID, arg.Alias)
	return err
}

const setTrackAliasPrimaryStatus = `-- name: SetTrackAliasPrimaryStatus :exec
UPDATE track_aliases SET is_primary = $1 WHERE track_id = $2 AND alias = $3
`

type SetTrackAliasPrimaryStatusParams struct {
	IsPrimary bool
	TrackID   int32
	Alias     string
}

func (q *Queries) SetTrackAliasPrimaryStatus(ctx context.Context, arg SetTrackAliasPrimaryStatusParams) error {
	_, err := q.db.Exec(ctx, setTrackAliasPrimaryStatus, arg.IsPrimary, arg.TrackID, arg.Alias)
	return err
}
