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

package v1_26

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

	"xorm.io/xorm"
)

// AddGiteaPagesTables adds the pages_domain and pages_config tables for Gitea Pages
func AddGiteaPagesTables(x *xorm.Engine) error {
	// PagesDomain represents a custom domain mapping for Gitea Pages
	type PagesDomain struct {
		ID                int64              `xorm:"pk autoincr"`
		RepoID            int64              `xorm:"INDEX NOT NULL"`
		Domain            string             `xorm:"UNIQUE NOT NULL"`
		Verified          bool               `xorm:"DEFAULT false"`
		VerificationToken string             `xorm:"VARCHAR(64)"`
		SSLStatus         string             `xorm:"VARCHAR(32) DEFAULT 'pending'"`
		SSLCertExpiry     timeutil.TimeStamp `xorm:"DEFAULT 0"`
		CreatedUnix       timeutil.TimeStamp `xorm:"created"`
		VerifiedUnix      timeutil.TimeStamp `xorm:"DEFAULT 0"`
	}

	// PagesConfig represents the cached configuration for a repository's landing page
	type PagesConfig struct {
		ID          int64              `xorm:"pk autoincr"`
		RepoID      int64              `xorm:"UNIQUE NOT NULL"`
		Enabled     bool               `xorm:"DEFAULT false"`
		Template    string             `xorm:"VARCHAR(32) DEFAULT 'simple'"`
		ConfigJSON  string             `xorm:"TEXT"`
		ConfigHash  string             `xorm:"VARCHAR(64)"`
		UpdatedUnix timeutil.TimeStamp `xorm:"updated"`
	}

	return x.Sync(new(PagesDomain), new(PagesConfig))
}
