// Copyright 2025 eat-pray-ai & OpenWaygate
// SPDX-License-Identifier: Apache-2.0

package video

import (
	"github.com/eat-pray-ai/yutu/cmd"
	"github.com/eat-pray-ai/yutu/pkg/utils"
	"github.com/spf13/pflag"

	"github.com/spf13/cobra"
)

const (
	short           = "Manage YouTube videos"
	long            = "Manage YouTube videos. Use this tool to list, upload, update, delete, get rating, or report videos."
	alUsage         = "Should auto-levels be applied to the upload"
	fileUsage       = "Path to the video file"
	titleUsage      = "Title of the video"
	descUsage       = "Description of the video"
	hlUsage         = "Specifies the localization language"
	tagsUsage       = "Comma separated tags"
	localeUsage     = "Locale of the video metadata to return"
	licenseUsage    = "youtube|creativeCommon"
	thumbnailUsage  = "Path to the thumbnail file"
	chartUsage      = "chartUnspecified|mostPopular"
	chidUsage       = "Channel id of the video"
	commentsUsage   = "Additional comments regarding the abuse report"
	pidUsage        = "Playlist id of the video"
	caidUsage       = "Category of the video"
	privacyUsage    = "public|private|unlisted"
	fkUsage         = "Whether the video is for kids"
	embeddableUsage = "Whether the video is embeddable"
	csmUsage        = "Whether the video contains altered or synthetic media"
	rdUsage         = "Date and time when the video was recorded"
	paUsage         = "Datetime when the video is scheduled to publish"
	rcUsage         = "Specific to the specified region"
	ridUsage        = "ID of the reason for reporting abuse"
	sridUsage       = "ID of the secondary reason for reporting abuse"
	stabilizeUsage  = "Should stabilize be applied to the upload"
	mhUsage         = "Max height of the embedded player in pixels"
	mwUsage         = "Max width of the embedded player in pixels"
	nsUsage         = "Notify the channel subscribers about the new video"
	psvUsage        = "Whether the extended video statistics can be viewed by everyone"
)

var (
	ids               []string
	autoLevels        = new(false)
	file              string
	title             string
	description       string
	hl                string
	tags              []string
	language          string
	locale            string
	license           string
	thumbnail         string
	rating            string
	chart             string
	channelId         string
	comments          string
	playListId        string
	categoryId        string
	privacy           string
	forKids           = new(false)
	embeddable        = new(false)
	recordingDate     string
	publishAt         string
	regionCode        string
	reasonId          string
	secondaryReasonId string
	stabilize         = new(false)
	maxHeight         int64
	maxWidth          int64
	maxResults        int64
	parts             []string

	notifySubscribers             = new(false)
	publicStatsViewable           = new(false)
	containsSyntheticMedia        = new(false)
	onBehalfOfContentOwner        string
	onBehalfOfContentOwnerChannel string
)

var videoCmd = &cobra.Command{
	Use:   "video",
	Short: short,
	Long:  long,
	PersistentPreRun: func(cmd *cobra.Command, args []string) {
		resetFlags(cmd.Flags())
	},
	Run: func(cmd *cobra.Command, args []string) {
		_ = cmd.Help()
	},
}

func init() {
	cmd.RootCmd.AddCommand(videoCmd)
}

func resetFlags(flagSet *pflag.FlagSet) {
	boolMap := map[string]**bool{
		"autoLevels":             &autoLevels,
		"forKids":                &forKids,
		"embeddable":             &embeddable,
		"containsSyntheticMedia": &containsSyntheticMedia,
		"stabilize":              &stabilize,
		"notifySubscribers":      &notifySubscribers,
		"publicStatsViewable":    &publicStatsViewable,
	}

	utils.ResetBool(boolMap, flagSet)
}
