package thrift

import (
	
	
	
	
)

type MissingField struct {
	Field Field
}

func ( *MissingField) () string {
	return fmt.Sprintf("missing required field: %s", .Field)
}

type TypeMismatch struct {
	Expect Type
	Found  Type
	item   string
}

func ( *TypeMismatch) () string {
	return fmt.Sprintf("%s type mismatch: expected %s but found %s", .item, .Expect, .Found)
}

type decodeError struct {
	base error
	path []error
}

func ( *decodeError) () string {
	 := strings.Builder{}
	.Grow(256)
	.WriteString("decoding thrift payload: ")

	if len(.path) != 0 {
		 := len(.path) - 1
		for  := ;  >= 0; -- {
			if  <  {
				.WriteString(" → ")
			}
			.WriteString(.path[].Error())
		}
		.WriteString(": ")
	}

	.WriteString(.base.Error())
	return .String()
}

func ( *decodeError) () error { return .base }

func with(,  error) error {
	if errors.Is(, io.EOF) {
		return 
	}
	,  := .(*decodeError)
	if  == nil {
		 = &decodeError{base: }
	}
	.path = append(.path, )
	return 
}

type decodeErrorField struct {
	cause Field
}

func ( *decodeErrorField) () string {
	return .cause.String()
}

type decodeErrorList struct {
	cause List
	index int
}

func ( *decodeErrorList) () string {
	return fmt.Sprintf("%d/%d:%s", .index, .cause.Size, .cause)
}

type decodeErrorSet struct {
	cause Set
	index int
}

func ( *decodeErrorSet) () string {
	return fmt.Sprintf("%d/%d:%s", .index, .cause.Size, .cause)
}

type decodeErrorMap struct {
	cause Map
	index int
}

func ( *decodeErrorMap) () string {
	return fmt.Sprintf("%d/%d:%s", .index, .cause.Size, .cause)
}

func dontExpectEOF( error) error {
	switch  {
	case nil:
		return nil
	case io.EOF:
		return io.ErrUnexpectedEOF
	default:
		return 
	}
}