package templates

import (
	"backend/internal/db/sqlc"

	"github.com/google/uuid"
	"github.com/jackc/pgx/v5/pgtype"
)

// TaskColumns defines the canonical left-to-right column order for the kanban board.
var TaskColumns = []sqlc.TaskStatus{
	sqlc.TaskStatusTodo,
	sqlc.TaskStatusInProgress,
	sqlc.TaskStatusInReview,
	sqlc.TaskStatusDone,
}

// TaskColumnLabels maps each TaskStatus to its human-readable column header label.
var TaskColumnLabels = map[sqlc.TaskStatus]string{
	sqlc.TaskStatusTodo:       "To do",
	sqlc.TaskStatusInProgress: "In progress",
	sqlc.TaskStatusInReview:   "In review",
	sqlc.TaskStatusDone:       "Done",
}

// TaskCreateForm carries submitted field values back to the template for
// repopulation on validation failure.
type TaskCreateForm struct {
	Title   string
	Status  string // holds the column status value, e.g. "todo"
	EtapeID string
}

// TaskCreateErrors holds per-field and general error messages for the task
// create form. An empty string means "no error for this field".
type TaskCreateErrors struct {
	Title   string
	General string
}

// TaskUpdateForm carries submitted field values back to the template for
// repopulation on validation failure.
type TaskUpdateForm struct {
	Title       string
	Description string
}

// TaskUpdateErrors holds per-field and general error messages for the task
// update/edit form. An empty string means "no error for this field".
type TaskUpdateErrors struct {
	Title       string
	Description string
	General     string
}

func taskEtapeIDString(id pgtype.UUID) string {
	if !id.Valid {
		return ""
	}
	return uuid.UUID(id.Bytes).String()
}
