package shared

App_Error_Code :: enum {
	None,
	Config,
	Network,
	Rate_Limit,
	Validation,
	Generation,
	Export,
	Storage,
}

App_Error :: struct {
	code: App_Error_Code,
	message: string,
	recoverable: bool,
}

ok :: proc() -> App_Error {
	return App_Error{code = .None, message = "", recoverable = false}
}

is_ok :: proc(err: App_Error) -> bool {
	return err.code == .None
}

new_error :: proc(code: App_Error_Code, message: string, recoverable: bool) -> App_Error {
	return App_Error{code = code, message = message, recoverable = recoverable}
}

config_error :: proc(message: string) -> App_Error {
	return new_error(.Config, message, false)
}

network_error :: proc(message: string) -> App_Error {
	return new_error(.Network, message, true)
}

rate_limit_error :: proc(message: string) -> App_Error {
	return new_error(.Rate_Limit, message, true)
}

validation_error :: proc(message: string) -> App_Error {
	return new_error(.Validation, message, false)
}

generation_error :: proc(message: string) -> App_Error {
	return new_error(.Generation, message, true)
}

should_retry :: proc(err: App_Error) -> bool {
	if err.code == .None {
		return false
	}
	if err.code == .Rate_Limit || err.code == .Network {
		return true
	}
	return err.recoverable
}
