feat: add assessment, privacy and support flows
This commit is contained in:
1 parent
ee3738ee73
commit
e4f24fa202
339 files changed
+56454
-1126
No files matched your search
@@ -0,0 +1,213 @@
|
||||
package domain
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"time"
|
||||
)
|
||||
|
||||
var ErrInvalidSupportPolicy = errors.New("invalid support policy")
|
||||
|
||||
const (
|
||||
// MaxSupportRequestWindow bounds the rolling-window quota that an
|
||||
// implementation must support and retain request events for.
|
||||
MaxSupportRequestWindow = 24 * time.Hour
|
||||
maxSupportResponseBusinessDays = BusinessDays(60)
|
||||
maxSupportRequestsPerWindow = int32(1000)
|
||||
supportBusinessCalendarV1 = int32(1)
|
||||
supportAppealsPerTargetV1 = int32(1)
|
||||
)
|
||||
|
||||
// SupportPolicyInput describes the operational targets and request budget for
|
||||
// support cases. Targets are operational goals, never legal deadlines.
|
||||
type SupportPolicyInput struct {
|
||||
SupportResponseDays BusinessDays
|
||||
ComplaintResponseDays BusinessDays
|
||||
ManualAssessmentResponseDays BusinessDays
|
||||
AppealResponseDays BusinessDays
|
||||
MaxRequestsPerWindow int32
|
||||
RequestWindow time.Duration
|
||||
MaxAppealsPerTarget int32
|
||||
PauseWhenWaitingForUser bool
|
||||
BusinessCalendarVersion int32
|
||||
}
|
||||
|
||||
// SupportPolicy is an immutable set of support-case operating rules. Its
|
||||
// calendar is versioned weekdays-only UTC and does not include public
|
||||
// holidays. Waiting for the user does not pause the target. Manual assessment
|
||||
// does not depend on C3 consent.
|
||||
type SupportPolicy struct {
|
||||
supportResponseDays BusinessDays
|
||||
complaintResponseDays BusinessDays
|
||||
manualAssessmentResponseDays BusinessDays
|
||||
appealResponseDays BusinessDays
|
||||
maxRequestsPerWindow int32
|
||||
requestWindow time.Duration
|
||||
maxAppealsPerTarget int32
|
||||
pauseWhenWaitingForUser bool
|
||||
businessCalendarVersion int32
|
||||
}
|
||||
|
||||
// NewSupportPolicy validates and freezes explicit support settings. The
|
||||
// caller still has to pin the containing product policy version when it
|
||||
// creates a response target.
|
||||
func NewSupportPolicy(input SupportPolicyInput) (SupportPolicy, error) {
|
||||
const location = "domain.NewSupportPolicy"
|
||||
for _, value := range []struct {
|
||||
name string
|
||||
days BusinessDays
|
||||
}{
|
||||
{name: "support response days", days: input.SupportResponseDays},
|
||||
{name: "complaint response days", days: input.ComplaintResponseDays},
|
||||
{name: "manual assessment response days", days: input.ManualAssessmentResponseDays},
|
||||
{name: "appeal response days", days: input.AppealResponseDays},
|
||||
} {
|
||||
if value.days < 1 || value.days > maxSupportResponseBusinessDays {
|
||||
return SupportPolicy{}, fmt.Errorf("%s - %s must be 1 to %d business days: %w",
|
||||
location, value.name, maxSupportResponseBusinessDays, ErrInvalidSupportPolicy)
|
||||
}
|
||||
}
|
||||
if input.MaxRequestsPerWindow < 1 || input.MaxRequestsPerWindow > maxSupportRequestsPerWindow {
|
||||
return SupportPolicy{}, fmt.Errorf("%s - request limit must be 1 to %d: %w",
|
||||
location, maxSupportRequestsPerWindow, ErrInvalidSupportPolicy)
|
||||
}
|
||||
if input.RequestWindow <= 0 || input.RequestWindow > MaxSupportRequestWindow || input.RequestWindow%time.Second != 0 {
|
||||
return SupportPolicy{}, fmt.Errorf("%s - request window must be whole seconds, positive, and no longer than 24 hours: %w",
|
||||
location, ErrInvalidSupportPolicy)
|
||||
}
|
||||
if input.MaxAppealsPerTarget != supportAppealsPerTargetV1 {
|
||||
return SupportPolicy{}, fmt.Errorf("%s - MVP allows exactly one appeal per target and type: %w",
|
||||
location, ErrInvalidSupportPolicy)
|
||||
}
|
||||
if input.PauseWhenWaitingForUser {
|
||||
return SupportPolicy{}, fmt.Errorf("%s - waiting for the user cannot pause an MVP response target: %w",
|
||||
location, ErrInvalidSupportPolicy)
|
||||
}
|
||||
if input.BusinessCalendarVersion != supportBusinessCalendarV1 {
|
||||
return SupportPolicy{}, fmt.Errorf("%s - unsupported business calendar version: %w",
|
||||
location, ErrInvalidSupportPolicy)
|
||||
}
|
||||
return SupportPolicy{
|
||||
supportResponseDays: input.SupportResponseDays,
|
||||
complaintResponseDays: input.ComplaintResponseDays,
|
||||
manualAssessmentResponseDays: input.ManualAssessmentResponseDays,
|
||||
appealResponseDays: input.AppealResponseDays,
|
||||
maxRequestsPerWindow: input.MaxRequestsPerWindow,
|
||||
requestWindow: input.RequestWindow,
|
||||
maxAppealsPerTarget: input.MaxAppealsPerTarget,
|
||||
pauseWhenWaitingForUser: input.PauseWhenWaitingForUser,
|
||||
businessCalendarVersion: input.BusinessCalendarVersion,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// DemoSupportPolicy returns explicit demo defaults. These values are not a
|
||||
// calibrated service commitment and do not describe a legal deadline.
|
||||
func DemoSupportPolicy() SupportPolicy {
|
||||
return SupportPolicy{
|
||||
supportResponseDays: 5,
|
||||
complaintResponseDays: 5,
|
||||
manualAssessmentResponseDays: 5,
|
||||
appealResponseDays: 10,
|
||||
maxRequestsPerWindow: 10,
|
||||
requestWindow: time.Hour,
|
||||
maxAppealsPerTarget: supportAppealsPerTargetV1,
|
||||
businessCalendarVersion: supportBusinessCalendarV1,
|
||||
}
|
||||
}
|
||||
|
||||
func (policy SupportPolicy) IsZero() bool {
|
||||
return policy.supportResponseDays == 0 || policy.complaintResponseDays == 0 ||
|
||||
policy.manualAssessmentResponseDays == 0 || policy.appealResponseDays == 0 ||
|
||||
policy.maxRequestsPerWindow == 0 || policy.requestWindow == 0 ||
|
||||
policy.maxAppealsPerTarget == 0 || policy.businessCalendarVersion == 0
|
||||
}
|
||||
|
||||
func (policy SupportPolicy) SupportResponseDays() BusinessDays {
|
||||
return policy.supportResponseDays
|
||||
}
|
||||
|
||||
func (policy SupportPolicy) ComplaintResponseDays() BusinessDays {
|
||||
return policy.complaintResponseDays
|
||||
}
|
||||
|
||||
func (policy SupportPolicy) ManualAssessmentResponseDays() BusinessDays {
|
||||
return policy.manualAssessmentResponseDays
|
||||
}
|
||||
|
||||
func (policy SupportPolicy) AppealResponseDays() BusinessDays {
|
||||
return policy.appealResponseDays
|
||||
}
|
||||
|
||||
func (policy SupportPolicy) MaxRequestsPerWindow() int32 { return policy.maxRequestsPerWindow }
|
||||
|
||||
func (policy SupportPolicy) RequestWindow() time.Duration { return policy.requestWindow }
|
||||
|
||||
// MaxAppealsPerTarget fixes the MVP rule: an appeal type may be opened once
|
||||
// for one target, regardless of the status of the first case.
|
||||
func (policy SupportPolicy) MaxAppealsPerTarget() int32 { return policy.maxAppealsPerTarget }
|
||||
|
||||
// PausesWhenWaitingForUser reports the fixed MVP rule that response targets
|
||||
// continue to run while a case waits for the author.
|
||||
func (policy SupportPolicy) PausesWhenWaitingForUser() bool { return policy.pauseWhenWaitingForUser }
|
||||
|
||||
func (policy SupportPolicy) BusinessCalendarVersion() int32 {
|
||||
return policy.businessCalendarVersion
|
||||
}
|
||||
|
||||
// ResponseTarget fixes the business-day target and its policy version at case
|
||||
// creation. Its UTC calendar excludes Saturdays and Sundays only.
|
||||
func (policy SupportPolicy) ResponseTarget(
|
||||
caseType SupportCaseType,
|
||||
policyVersion int32,
|
||||
createdAt time.Time,
|
||||
) (SupportResponseTarget, error) {
|
||||
const location = "SupportPolicy.ResponseTarget"
|
||||
if policy.IsZero() {
|
||||
return SupportResponseTarget{}, fmt.Errorf("%s - policy must be set: %w", location, ErrInvalidSupportPolicy)
|
||||
}
|
||||
if policyVersion < 1 || createdAt.IsZero() {
|
||||
return SupportResponseTarget{}, fmt.Errorf("%s - version and creation time must be set: %w", location, ErrInvalidSupportPolicy)
|
||||
}
|
||||
days, err := policy.responseDays(caseType)
|
||||
if err != nil {
|
||||
return SupportResponseTarget{}, fmt.Errorf("%s - resolve response target: %w", location, err)
|
||||
}
|
||||
dueAt := addWeekdaysUTC(createdAt, days)
|
||||
target, err := NewSupportResponseTarget(SupportResponseTargetSnapshot{
|
||||
BusinessDays: days,
|
||||
DueAt: dueAt,
|
||||
PolicyVersion: policyVersion,
|
||||
CalendarVersion: policy.BusinessCalendarVersion(),
|
||||
})
|
||||
if err != nil {
|
||||
return SupportResponseTarget{}, fmt.Errorf("%s - build response target: %w", location, err)
|
||||
}
|
||||
return target, nil
|
||||
}
|
||||
|
||||
func (policy SupportPolicy) responseDays(caseType SupportCaseType) (BusinessDays, error) {
|
||||
switch caseType {
|
||||
case SupportCaseTypeSupport:
|
||||
return policy.supportResponseDays, nil
|
||||
case SupportCaseTypeComplaint:
|
||||
return policy.complaintResponseDays, nil
|
||||
case SupportCaseTypeManualAssessment:
|
||||
return policy.manualAssessmentResponseDays, nil
|
||||
case SupportCaseTypeGradeAppeal, SupportCaseTypeAnticheatAppeal:
|
||||
return policy.appealResponseDays, nil
|
||||
default:
|
||||
return 0, fmt.Errorf("unknown case type: %w", ErrInvalidSupportPolicy)
|
||||
}
|
||||
}
|
||||
|
||||
func addWeekdaysUTC(start time.Time, days BusinessDays) time.Time {
|
||||
dueAt := start.UTC()
|
||||
remaining := int(days)
|
||||
for remaining > 0 {
|
||||
dueAt = dueAt.AddDate(0, 0, 1)
|
||||
if dueAt.Weekday() != time.Saturday && dueAt.Weekday() != time.Sunday {
|
||||
remaining--
|
||||
}
|
||||
}
|
||||
return dueAt
|
||||
}
|
||||
Reference in new issue
Block a user