// Copyright 2026 MarketAlly. All rights reserved.
// SPDX-License-Identifier: MIT

package v1_26

import (
	"code.gitea.io/gitea/modules/timeutil"

	"xorm.io/xorm"
)

// AddOrgPinnedTables adds the org_pinned_group and org_pinned_repo tables
// for organization profile pinned repositories feature
func AddOrgPinnedTables(x *xorm.Engine) error {
	type OrgPinnedGroup struct {
		ID           int64              `xorm:"pk autoincr"`
		OrgID        int64              `xorm:"INDEX NOT NULL"`
		Name         string             `xorm:"NOT NULL"`
		DisplayOrder int                `xorm:"DEFAULT 0"`
		Collapsed    bool               `xorm:"DEFAULT false"`
		CreatedUnix  timeutil.TimeStamp `xorm:"created"`
		UpdatedUnix  timeutil.TimeStamp `xorm:"updated"`
	}

	type OrgPinnedRepo struct {
		ID           int64              `xorm:"pk autoincr"`
		OrgID        int64              `xorm:"INDEX NOT NULL"`
		RepoID       int64              `xorm:"INDEX NOT NULL"`
		GroupID      int64              `xorm:"INDEX"`
		DisplayOrder int                `xorm:"DEFAULT 0"`
		CreatedUnix  timeutil.TimeStamp `xorm:"created"`
	}

	return x.Sync(new(OrgPinnedGroup), new(OrgPinnedRepo))
}
