package api

import "github.com/tidbcloud/alertstore/pkg/directory"

// The shapes every handler answers with, named so the generated OpenAPI
// contract describes them and the compiler keeps them in step. An inline
// gin.H serializes the same bytes, but nothing then stops one handler from
// spelling a field differently from the rest, and the generated client would
// inherit the drift.

// ErrorResponse is the body of every non-2xx answer.
type ErrorResponse struct {
	Error string `json:"error" validate:"required"`
}

// StatusResponse is the body of a mutation that has nothing to return but its
// own success.
type StatusResponse struct {
	Status string `json:"status" example:"ok" validate:"required"`
}

// UsersResponse wraps the assignee suggestions. The list is wrapped rather
// than returned bare so the endpoint can grow a cursor without breaking the
// clients generated from this contract.
type UsersResponse struct {
	Users []directory.User `json:"users" validate:"required"`
}

// errorBody builds the standard error payload.
func errorBody(err error) ErrorResponse {
	return ErrorResponse{Error: err.Error()}
}

// errorMessage builds the standard error payload from a fixed string, for the
// cases that report a condition rather than a failed call.
func errorMessage(msg string) ErrorResponse {
	return ErrorResponse{Error: msg}
}

// okStatus is the body shared by every mutation that returns no entity.
func okStatus() StatusResponse {
	return StatusResponse{Status: "ok"}
}
