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

package v1_27

import (
	"xorm.io/xorm"
)

// AddIssueStatusDefTable creates the issue_status_def table and adds
// status_id to the issue table.
func AddIssueStatusDefTable(x *xorm.Engine) error {
	type IssueStatusDef 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"`
		ClosesIssue bool   `xorm:"NOT NULL DEFAULT false 'closes_issue'"`
		SortOrder   int    `xorm:"NOT NULL DEFAULT 0 'sort_order'"`
		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(IssueStatusDef)); err != nil {
		return err
	}

	// Add status_id column to issue table
	type Issue struct {
		StatusID int64 `xorm:"INDEX NOT NULL DEFAULT 0 'status_id'"`
	}
	return x.Sync(new(Issue))
}
