package rest

import (
	"git.ali33.ru/fcg-xvii/go-tools/json"
)

type IResponse interface {
	IsError() bool
	KeySet(key string, val any)
	FileSet(name string, file IReadCloserLen)
	Close()
	Send(writer any) IErrorArgs
}

type Response struct {
	code  int
	err   IErrorArgs
	data  json.Map
	files map[string]IReadCloserLen
}

func (s *Response) IsError() bool {
	return s.code != 200
}

func (s *Response) KeySet(key string, val any) {
	s.data[key] = val
}

func (s *Response) FileSet(name string, file IReadCloserLen) {
	s.files[name] = file
}

func (s *Response) Close() {
	for _, file := range s.files {
		file.Close()
	}
}

func (s *Response) Send(writer any) IErrorArgs {
	return nil
}

func (s *Response) Code() int {
	return s.code
}

func (s *Response) Data() json.Map {
	return s.data
}

func (s *Response) Files() map[string]IReadCloserLen {
	return s.files
}

func (s *Response) Err() IErrorArgs {
	return s.err
}
