package models

type Place struct {
	Code         string         `json:"code"`
	Name         string         `json:"name"`
	Text         string         `json:"text"`
	Image        string         `json:"image"`
	Applications []*Application `json:"applications,omitempty"`
	Hidden       bool           `json:"hidden"`
	Doors        []*Door        `json:"doors"`
}

func NewPlace(
	code string,
	name string,
	text string,
	opts ...PlaceOpt,
) *Place {
	p := &Place{
		Code: code,
		Name: name,
		Text: text,
	}
	for _, opt := range opts {
		opt(p)
	}
	return p
}

func NewNotFoundPlace(code string) *Place {
	return NewPlace(code, "Не найдено", "Такой точки не существует.")
}

func NewClientErrorPlace(code string) *Place {
	return NewPlace(code, "Не найдено", "Детективы, внимательно читайте правила.")
}

type PlaceOpt func(place *Place) error

func WithPlaceImage(image string) PlaceOpt {
	return func(place *Place) error {
		place.Image = image
		return nil
	}
}

func WithPlaceApplication(applications ...*Application) PlaceOpt {
	return func(place *Place) error {
		for _, application := range applications {
			place.Applications = append(place.Applications, application)
		}
		return nil
	}
}

func WithPlaceHidden(hidden bool) PlaceOpt {
	return func(place *Place) error {
		place.Hidden = hidden
		return nil
	}
}

func WithPlaceDoors(doors ...*Door) PlaceOpt {
	return func(place *Place) error {
		for _, door := range doors {
			place.Doors = append(place.Doors, door)
		}
		return nil
	}
}
