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

package dbgen

import (
	"context"

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

const ArchiveSubCourseVideo = `-- name: ArchiveSubCourseVideo :exec
UPDATE sub_course_videos
SET status = 'ARCHIVED'
WHERE id = $1
`

func (q *Queries) ArchiveSubCourseVideo(ctx context.Context, id int64) error {
	_, err := q.db.Exec(ctx, ArchiveSubCourseVideo, id)
	return err
}

const CreateSubCourseVideo = `-- name: CreateSubCourseVideo :one
INSERT INTO sub_course_videos (
    sub_course_id,
    title,
    description,
    video_url,
    duration,
    resolution,
    instructor_id,
    thumbnail,
    visibility,
    display_order,
    status,
    vimeo_id,
    vimeo_embed_url,
    vimeo_player_html,
    vimeo_status,
    video_host_provider
)
VALUES (
    $1, $2, $3, $4, $5, $6,
    $7, $8, $9,
    COALESCE($10, 0),
    COALESCE($11, 'DRAFT'),
    $12, $13, $14,
    COALESCE($15, 'pending'),
    COALESCE($16, 'DIRECT')
)
RETURNING id, sub_course_id, title, description, video_url, duration, resolution, is_published, publish_date, visibility, instructor_id, thumbnail, display_order, status, vimeo_id, vimeo_embed_url, vimeo_player_html, vimeo_status, video_host_provider
`

type CreateSubCourseVideoParams struct {
	SubCourseID     int64       `json:"sub_course_id"`
	Title           string      `json:"title"`
	Description     pgtype.Text `json:"description"`
	VideoUrl        string      `json:"video_url"`
	Duration        int32       `json:"duration"`
	Resolution      pgtype.Text `json:"resolution"`
	InstructorID    pgtype.Text `json:"instructor_id"`
	Thumbnail       pgtype.Text `json:"thumbnail"`
	Visibility      pgtype.Text `json:"visibility"`
	Column10        interface{} `json:"column_10"`
	Column11        interface{} `json:"column_11"`
	VimeoID         pgtype.Text `json:"vimeo_id"`
	VimeoEmbedUrl   pgtype.Text `json:"vimeo_embed_url"`
	VimeoPlayerHtml pgtype.Text `json:"vimeo_player_html"`
	Column15        interface{} `json:"column_15"`
	Column16        interface{} `json:"column_16"`
}

func (q *Queries) CreateSubCourseVideo(ctx context.Context, arg CreateSubCourseVideoParams) (SubCourseVideo, error) {
	row := q.db.QueryRow(ctx, CreateSubCourseVideo,
		arg.SubCourseID,
		arg.Title,
		arg.Description,
		arg.VideoUrl,
		arg.Duration,
		arg.Resolution,
		arg.InstructorID,
		arg.Thumbnail,
		arg.Visibility,
		arg.Column10,
		arg.Column11,
		arg.VimeoID,
		arg.VimeoEmbedUrl,
		arg.VimeoPlayerHtml,
		arg.Column15,
		arg.Column16,
	)
	var i SubCourseVideo
	err := row.Scan(
		&i.ID,
		&i.SubCourseID,
		&i.Title,
		&i.Description,
		&i.VideoUrl,
		&i.Duration,
		&i.Resolution,
		&i.IsPublished,
		&i.PublishDate,
		&i.Visibility,
		&i.InstructorID,
		&i.Thumbnail,
		&i.DisplayOrder,
		&i.Status,
		&i.VimeoID,
		&i.VimeoEmbedUrl,
		&i.VimeoPlayerHtml,
		&i.VimeoStatus,
		&i.VideoHostProvider,
	)
	return i, err
}

const DeleteSubCourseVideo = `-- name: DeleteSubCourseVideo :exec
DELETE FROM sub_course_videos
WHERE id = $1
`

func (q *Queries) DeleteSubCourseVideo(ctx context.Context, id int64) error {
	_, err := q.db.Exec(ctx, DeleteSubCourseVideo, id)
	return err
}

const GetPublishedVideosBySubCourse = `-- name: GetPublishedVideosBySubCourse :many
SELECT id, sub_course_id, title, description, video_url, duration, resolution, is_published, publish_date, visibility, instructor_id, thumbnail, display_order, status, vimeo_id, vimeo_embed_url, vimeo_player_html, vimeo_status, video_host_provider
FROM sub_course_videos
WHERE sub_course_id = $1
  AND status = 'PUBLISHED'
ORDER BY display_order ASC, publish_date ASC
`

func (q *Queries) GetPublishedVideosBySubCourse(ctx context.Context, subCourseID int64) ([]SubCourseVideo, error) {
	rows, err := q.db.Query(ctx, GetPublishedVideosBySubCourse, subCourseID)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	var items []SubCourseVideo
	for rows.Next() {
		var i SubCourseVideo
		if err := rows.Scan(
			&i.ID,
			&i.SubCourseID,
			&i.Title,
			&i.Description,
			&i.VideoUrl,
			&i.Duration,
			&i.Resolution,
			&i.IsPublished,
			&i.PublishDate,
			&i.Visibility,
			&i.InstructorID,
			&i.Thumbnail,
			&i.DisplayOrder,
			&i.Status,
			&i.VimeoID,
			&i.VimeoEmbedUrl,
			&i.VimeoPlayerHtml,
			&i.VimeoStatus,
			&i.VideoHostProvider,
		); err != nil {
			return nil, err
		}
		items = append(items, i)
	}
	if err := rows.Err(); err != nil {
		return nil, err
	}
	return items, nil
}

const GetSubCourseVideoByID = `-- name: GetSubCourseVideoByID :one
SELECT id, sub_course_id, title, description, video_url, duration, resolution, is_published, publish_date, visibility, instructor_id, thumbnail, display_order, status, vimeo_id, vimeo_embed_url, vimeo_player_html, vimeo_status, video_host_provider
FROM sub_course_videos
WHERE id = $1
`

func (q *Queries) GetSubCourseVideoByID(ctx context.Context, id int64) (SubCourseVideo, error) {
	row := q.db.QueryRow(ctx, GetSubCourseVideoByID, id)
	var i SubCourseVideo
	err := row.Scan(
		&i.ID,
		&i.SubCourseID,
		&i.Title,
		&i.Description,
		&i.VideoUrl,
		&i.Duration,
		&i.Resolution,
		&i.IsPublished,
		&i.PublishDate,
		&i.Visibility,
		&i.InstructorID,
		&i.Thumbnail,
		&i.DisplayOrder,
		&i.Status,
		&i.VimeoID,
		&i.VimeoEmbedUrl,
		&i.VimeoPlayerHtml,
		&i.VimeoStatus,
		&i.VideoHostProvider,
	)
	return i, err
}

const GetVideosBySubCourse = `-- name: GetVideosBySubCourse :many
SELECT
    COUNT(*) OVER () AS total_count,
    id,
    sub_course_id,
    title,
    description,
    video_url,
    duration,
    resolution,
    is_published,
    publish_date,
    visibility,
    instructor_id,
    thumbnail,
    display_order,
    status,
    vimeo_id,
    vimeo_embed_url,
    vimeo_player_html,
    vimeo_status,
    video_host_provider
FROM sub_course_videos
WHERE sub_course_id = $1
  AND status != 'ARCHIVED'
ORDER BY display_order ASC, id ASC
`

type GetVideosBySubCourseRow struct {
	TotalCount        int64              `json:"total_count"`
	ID                int64              `json:"id"`
	SubCourseID       int64              `json:"sub_course_id"`
	Title             string             `json:"title"`
	Description       pgtype.Text        `json:"description"`
	VideoUrl          string             `json:"video_url"`
	Duration          int32              `json:"duration"`
	Resolution        pgtype.Text        `json:"resolution"`
	IsPublished       bool               `json:"is_published"`
	PublishDate       pgtype.Timestamptz `json:"publish_date"`
	Visibility        pgtype.Text        `json:"visibility"`
	InstructorID      pgtype.Text        `json:"instructor_id"`
	Thumbnail         pgtype.Text        `json:"thumbnail"`
	DisplayOrder      int32              `json:"display_order"`
	Status            string             `json:"status"`
	VimeoID           pgtype.Text        `json:"vimeo_id"`
	VimeoEmbedUrl     pgtype.Text        `json:"vimeo_embed_url"`
	VimeoPlayerHtml   pgtype.Text        `json:"vimeo_player_html"`
	VimeoStatus       pgtype.Text        `json:"vimeo_status"`
	VideoHostProvider pgtype.Text        `json:"video_host_provider"`
}

func (q *Queries) GetVideosBySubCourse(ctx context.Context, subCourseID int64) ([]GetVideosBySubCourseRow, error) {
	rows, err := q.db.Query(ctx, GetVideosBySubCourse, subCourseID)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	var items []GetVideosBySubCourseRow
	for rows.Next() {
		var i GetVideosBySubCourseRow
		if err := rows.Scan(
			&i.TotalCount,
			&i.ID,
			&i.SubCourseID,
			&i.Title,
			&i.Description,
			&i.VideoUrl,
			&i.Duration,
			&i.Resolution,
			&i.IsPublished,
			&i.PublishDate,
			&i.Visibility,
			&i.InstructorID,
			&i.Thumbnail,
			&i.DisplayOrder,
			&i.Status,
			&i.VimeoID,
			&i.VimeoEmbedUrl,
			&i.VimeoPlayerHtml,
			&i.VimeoStatus,
			&i.VideoHostProvider,
		); err != nil {
			return nil, err
		}
		items = append(items, i)
	}
	if err := rows.Err(); err != nil {
		return nil, err
	}
	return items, nil
}

const GetVideosByVimeoID = `-- name: GetVideosByVimeoID :one
SELECT id, sub_course_id, title, description, video_url, duration, resolution, is_published, publish_date, visibility, instructor_id, thumbnail, display_order, status, vimeo_id, vimeo_embed_url, vimeo_player_html, vimeo_status, video_host_provider FROM sub_course_videos
WHERE vimeo_id = $1
`

func (q *Queries) GetVideosByVimeoID(ctx context.Context, vimeoID pgtype.Text) (SubCourseVideo, error) {
	row := q.db.QueryRow(ctx, GetVideosByVimeoID, vimeoID)
	var i SubCourseVideo
	err := row.Scan(
		&i.ID,
		&i.SubCourseID,
		&i.Title,
		&i.Description,
		&i.VideoUrl,
		&i.Duration,
		&i.Resolution,
		&i.IsPublished,
		&i.PublishDate,
		&i.Visibility,
		&i.InstructorID,
		&i.Thumbnail,
		&i.DisplayOrder,
		&i.Status,
		&i.VimeoID,
		&i.VimeoEmbedUrl,
		&i.VimeoPlayerHtml,
		&i.VimeoStatus,
		&i.VideoHostProvider,
	)
	return i, err
}

const PublishSubCourseVideo = `-- name: PublishSubCourseVideo :exec
UPDATE sub_course_videos
SET
    is_published = true,
    publish_date = CURRENT_TIMESTAMP,
    status = 'PUBLISHED'
WHERE id = $1
`

func (q *Queries) PublishSubCourseVideo(ctx context.Context, id int64) error {
	_, err := q.db.Exec(ctx, PublishSubCourseVideo, id)
	return err
}

const UpdateSubCourseVideo = `-- name: UpdateSubCourseVideo :exec
UPDATE sub_course_videos
SET
    title = COALESCE($1, title),
    description = COALESCE($2, description),
    video_url = COALESCE($3, video_url),
    duration = COALESCE($4, duration),
    resolution = COALESCE($5, resolution),
    visibility = COALESCE($6, visibility),
    thumbnail = COALESCE($7, thumbnail),
    display_order = COALESCE($8, display_order),
    status = COALESCE($9, status),
    vimeo_id = COALESCE($10, vimeo_id),
    vimeo_embed_url = COALESCE($11, vimeo_embed_url),
    vimeo_player_html = COALESCE($12, vimeo_player_html),
    vimeo_status = COALESCE($13, vimeo_status),
    video_host_provider = COALESCE($14, video_host_provider)
WHERE id = $15
`

type UpdateSubCourseVideoParams struct {
	Title             string      `json:"title"`
	Description       pgtype.Text `json:"description"`
	VideoUrl          string      `json:"video_url"`
	Duration          int32       `json:"duration"`
	Resolution        pgtype.Text `json:"resolution"`
	Visibility        pgtype.Text `json:"visibility"`
	Thumbnail         pgtype.Text `json:"thumbnail"`
	DisplayOrder      int32       `json:"display_order"`
	Status            string      `json:"status"`
	VimeoID           pgtype.Text `json:"vimeo_id"`
	VimeoEmbedUrl     pgtype.Text `json:"vimeo_embed_url"`
	VimeoPlayerHtml   pgtype.Text `json:"vimeo_player_html"`
	VimeoStatus       pgtype.Text `json:"vimeo_status"`
	VideoHostProvider pgtype.Text `json:"video_host_provider"`
	ID                int64       `json:"id"`
}

func (q *Queries) UpdateSubCourseVideo(ctx context.Context, arg UpdateSubCourseVideoParams) error {
	_, err := q.db.Exec(ctx, UpdateSubCourseVideo,
		arg.Title,
		arg.Description,
		arg.VideoUrl,
		arg.Duration,
		arg.Resolution,
		arg.Visibility,
		arg.Thumbnail,
		arg.DisplayOrder,
		arg.Status,
		arg.VimeoID,
		arg.VimeoEmbedUrl,
		arg.VimeoPlayerHtml,
		arg.VimeoStatus,
		arg.VideoHostProvider,
		arg.ID,
	)
	return err
}

const UpdateVimeoStatus = `-- name: UpdateVimeoStatus :exec
UPDATE sub_course_videos
SET
    vimeo_status = $1
WHERE id = $2
`

type UpdateVimeoStatusParams struct {
	VimeoStatus pgtype.Text `json:"vimeo_status"`
	ID          int64       `json:"id"`
}

func (q *Queries) UpdateVimeoStatus(ctx context.Context, arg UpdateVimeoStatusParams) error {
	_, err := q.db.Exec(ctx, UpdateVimeoStatus, arg.VimeoStatus, arg.ID)
	return err
}
