// Copyright 2026 Moko Consulting <hello@mokoconsulting.tech>
// SPDX-License-Identifier: GPL-3.0-or-later

package v1_27

import (
	"code.mokoconsulting.tech/MokoConsulting/MokoGitea/modules/timeutil"

	"xorm.io/xorm"
)

type customFieldDef343 struct {
	ID          int64              `xorm:"pk autoincr"`
	RepoID      int64              `xorm:"INDEX NOT NULL 'repo_id'"`
	Name        string             `xorm:"NOT NULL"`
	FieldType   string             `xorm:"VARCHAR(20) NOT NULL 'field_type'"`
	Description string             `xorm:"TEXT"`
	Options     string             `xorm:"TEXT"`
	Required    bool               `xorm:"NOT NULL DEFAULT false"`
	SortOrder   int                `xorm:"NOT NULL DEFAULT 0 'sort_order'"`
	IsActive    bool               `xorm:"NOT NULL DEFAULT true 'is_active'"`
	CreatedUnix timeutil.TimeStamp `xorm:"INDEX CREATED 'created_unix'"`
	UpdatedUnix timeutil.TimeStamp `xorm:"UPDATED 'updated_unix'"`
}

func (customFieldDef343) TableName() string {
	return "custom_field_def"
}

type customFieldValue343 struct {
	ID          int64              `xorm:"pk autoincr"`
	IssueID     int64              `xorm:"INDEX NOT NULL 'issue_id'"`
	FieldID     int64              `xorm:"INDEX NOT NULL 'field_id'"`
	Value       string             `xorm:"TEXT"`
	CreatedUnix timeutil.TimeStamp `xorm:"INDEX CREATED 'created_unix'"`
	UpdatedUnix timeutil.TimeStamp `xorm:"UPDATED 'updated_unix'"`
}

func (customFieldValue343) TableName() string {
	return "custom_field_value"
}

// AddCustomFieldTables creates the custom_field_def and custom_field_value tables.
func AddCustomFieldTables(x *xorm.Engine) error {
	return x.Sync(new(customFieldDef343), new(customFieldValue343))
}
