package mail

import (
	"strings"

	"github.com/ultisuite/ulti-backend/internal/api/apivalidate"
)

const maxUnifiedFolderRequestBody = 8 << 10

type createUnifiedFolderRequest struct {
	Name       string `json:"name"`
	Color      string `json:"color"`
	AccountID  string `json:"account_id"`
	ParentID   string `json:"parent_id"`
	SortOrder  int    `json:"sort_order"`
}

type updateUnifiedFolderRequest struct {
	Name      string  `json:"name"`
	Color     string  `json:"color"`
	SortOrder int     `json:"sort_order"`
	ParentID  *string `json:"parent_id"`
}

func validateCreateUnifiedFolder(req *createUnifiedFolderRequest) *apivalidate.ValidationError {
	if req == nil {
		return apivalidate.NewValidationError(apivalidate.FieldDetail{Field: "body", Message: "required"})
	}
	if strings.TrimSpace(req.Name) == "" {
		return apivalidate.NewValidationError(apivalidate.FieldDetail{Field: "name", Message: "required"})
	}
	if len(req.Name) > maxFolderName {
		return apivalidate.NewValidationError(apivalidate.FieldDetail{Field: "name", Message: "too long"})
	}
	return nil
}

func validateUpdateUnifiedFolder(req *updateUnifiedFolderRequest) *apivalidate.ValidationError {
	if req == nil {
		return apivalidate.NewValidationError(apivalidate.FieldDetail{Field: "body", Message: "required"})
	}
	if strings.TrimSpace(req.Name) == "" {
		return apivalidate.NewValidationError(apivalidate.FieldDetail{Field: "name", Message: "required"})
	}
	return nil
}
