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

package v1_27

import "xorm.io/xorm"

// AddIssueTypeDefTable creates the issue_type_def table and adds type_id to issues.
func AddIssueTypeDefTable(x *xorm.Engine) error {
	type IssueTypeDef struct {
		ID          int64  `xorm:"pk autoincr"`
		OrgID       int64  `xorm:"INDEX NOT NULL DEFAULT 0 'org_id'"`
		Name        string `xorm:"NOT NULL"`
		Color       string `xorm:"VARCHAR(7)"`
		Description string `xorm:"TEXT"`
		SortOrder   int    `xorm:"NOT NULL DEFAULT 0 'sort_order'"`
		IsDefault   bool   `xorm:"NOT NULL DEFAULT false 'is_default'"`
		IsActive    bool   `xorm:"NOT NULL DEFAULT true 'is_active'"`
		CreatedUnix int64  `xorm:"INDEX CREATED 'created_unix'"`
		UpdatedUnix int64  `xorm:"UPDATED 'updated_unix'"`
	}
	if err := x.Sync(new(IssueTypeDef)); err != nil {
		return err
	}
	type Issue struct {
		TypeID int64 `xorm:"INDEX NOT NULL DEFAULT 0 'type_id'"`
	}
	return x.Sync(new(Issue))
}
