package migrations

import (
	"github.com/pocketbase/pocketbase/core"
	m "github.com/pocketbase/pocketbase/migrations"
)

func init() {
	m.Register(func(app core.App) error {
		collection, err := app.FindCollectionByNameOrId("users")
		if err != nil {
			return err
		}

		// Enable OAuth2
		collection.OAuth2.Enabled = true

		// Optional: Map fields if necessary, for now just enabling it
		// collection.OAuth2.MappedFields.Name = "name"

		return app.Save(collection)
	}, func(app core.App) error {
		collection, err := app.FindCollectionByNameOrId("users")
		if err != nil {
			return err
		}

		collection.OAuth2.Enabled = false

		return app.Save(collection)
	})
}
