package sign

import "eq2emu/internal/spawn"

// Sign represents a clickable sign in the game world that extends Spawn
type Sign struct {
	*spawn.Spawn // Embed spawn for basic functionality

	// Widget properties
	widgetID int32   // Widget identifier
	widgetX  float32 // Widget X coordinate
	widgetY  float32 // Widget Y coordinate
	widgetZ  float32 // Widget Z coordinate

	// Sign properties
	signType    int8   // Type of sign (generic or zone)
	title       string // Sign title
	description string // Sign description
	language    int8   // Language of the sign text

	// Zone transport properties
	zoneX        float32 // Target zone X coordinate
	zoneY        float32 // Target zone Y coordinate
	zoneZ        float32 // Target zone Z coordinate
	zoneHeading  float32 // Target zone heading
	zoneID       int32   // Target zone ID
	signDistance float32 // Maximum interaction distance

	// Display options
	includeLocation bool // Whether to include location in display
	includeHeading  bool // Whether to include heading in display
}

// NewSign creates a new sign with default values
func NewSign() *Sign {
	baseSpawn := spawn.NewSpawn()

	// Set spawn-specific defaults for signs
	baseSpawn.SetSpawnType(DefaultSpawnType)
	// TODO: Set appearance properties when spawn system is integrated
	// appearance.pos.state = DefaultPosState
	// appearance.difficulty = DefaultDifficulty
	// appearance.activity_status = DefaultActivityStatus

	return &Sign{
		Spawn:           baseSpawn,
		widgetID:        0,
		widgetX:         0,
		widgetY:         0,
		widgetZ:         0,
		signType:        SignTypeGeneric,
		title:           "",
		description:     "",
		language:        0,
		zoneX:           0,
		zoneY:           0,
		zoneZ:           0,
		zoneHeading:     0,
		zoneID:          0,
		signDistance:    DefaultSignDistance,
		includeLocation: false,
		includeHeading:  false,
	}
}

// IsSign returns true since this is a sign
func (s *Sign) IsSign() bool {
	return true
}

// Widget ID methods
func (s *Sign) GetWidgetID() int32 {
	return s.widgetID
}

func (s *Sign) SetWidgetID(id int32) {
	s.widgetID = id
}

// Widget position methods
func (s *Sign) GetWidgetX() float32 {
	return s.widgetX
}

func (s *Sign) SetWidgetX(x float32) {
	s.widgetX = x
}

func (s *Sign) GetWidgetY() float32 {
	return s.widgetY
}

func (s *Sign) SetWidgetY(y float32) {
	s.widgetY = y
}

func (s *Sign) GetWidgetZ() float32 {
	return s.widgetZ
}

func (s *Sign) SetWidgetZ(z float32) {
	s.widgetZ = z
}

// Sign type methods
func (s *Sign) GetSignType() int8 {
	return s.signType
}

func (s *Sign) SetSignType(signType int8) {
	s.signType = signType
}

// Title and description methods
func (s *Sign) GetSignTitle() string {
	return s.title
}

func (s *Sign) SetSignTitle(title string) {
	s.title = title
}

func (s *Sign) GetSignDescription() string {
	return s.description
}

func (s *Sign) SetSignDescription(description string) {
	s.description = description
}

// Language methods
func (s *Sign) GetLanguage() int8 {
	return s.language
}

func (s *Sign) SetLanguage(language int8) {
	s.language = language
}

// Zone transport methods
func (s *Sign) GetSignZoneX() float32 {
	return s.zoneX
}

func (s *Sign) SetSignZoneX(x float32) {
	s.zoneX = x
}

func (s *Sign) GetSignZoneY() float32 {
	return s.zoneY
}

func (s *Sign) SetSignZoneY(y float32) {
	s.zoneY = y
}

func (s *Sign) GetSignZoneZ() float32 {
	return s.zoneZ
}

func (s *Sign) SetSignZoneZ(z float32) {
	s.zoneZ = z
}

func (s *Sign) GetSignZoneHeading() float32 {
	return s.zoneHeading
}

func (s *Sign) SetSignZoneHeading(heading float32) {
	s.zoneHeading = heading
}

func (s *Sign) GetSignZoneID() int32 {
	return s.zoneID
}

func (s *Sign) SetSignZoneID(zoneID int32) {
	s.zoneID = zoneID
}

func (s *Sign) GetSignDistance() float32 {
	return s.signDistance
}

func (s *Sign) SetSignDistance(distance float32) {
	s.signDistance = distance
}

// Display option methods
func (s *Sign) GetIncludeLocation() bool {
	return s.includeLocation
}

func (s *Sign) SetIncludeLocation(include bool) {
	s.includeLocation = include
}

func (s *Sign) GetIncludeHeading() bool {
	return s.includeHeading
}

func (s *Sign) SetIncludeHeading(include bool) {
	s.includeHeading = include
}

// SetSignIcon sets the sign's icon (delegates to spawn appearance)
func (s *Sign) SetSignIcon(icon int8) {
	// TODO: Implement when spawn appearance system is integrated
	// s.appearance.icon = icon
}

// HasZoneCoordinates returns true if the sign has valid zone coordinates
func (s *Sign) HasZoneCoordinates() bool {
	return !(s.zoneX == 0 && s.zoneY == 0 && s.zoneZ == 0 && s.zoneHeading == 0)
}

// HasTitle returns true if the sign has a title
func (s *Sign) HasTitle() bool {
	return len(s.title) > 0
}

// HasDescription returns true if the sign has a description
func (s *Sign) HasDescription() bool {
	return len(s.description) > 0
}

// IsZoneSign returns true if this is a zone transport sign
func (s *Sign) IsZoneSign() bool {
	return s.signType == SignTypeZone
}

// IsGenericSign returns true if this is a generic sign
func (s *Sign) IsGenericSign() bool {
	return s.signType == SignTypeGeneric
}
